mirror of
https://gitlab.com/vylion/velascobot.git
synced 2025-04-19 21:46:35 +02:00
Velasco 2.3
- Fixed some problems with the new periodical replies - Merged last 2 commits properly
This commit is contained in:
parent
19f89d3ea9
commit
82d5863d27
2 changed files with 8 additions and 10 deletions
|
@ -72,7 +72,6 @@ class Chatlog(object):
|
|||
return False
|
||||
return rand <= self.answer
|
||||
|
||||
<<<<<<< Updated upstream
|
||||
def add_replyable(self, msg_id):
|
||||
self.replyables.append(msg_id)
|
||||
|
||||
|
@ -84,13 +83,11 @@ class Chatlog(object):
|
|||
|
||||
def get_replyable(self):
|
||||
random.choice(self.replyables)
|
||||
=======
|
||||
def toggle_restrict(self):
|
||||
self.restricted = (not self.restricted)
|
||||
|
||||
def is_restricted(self):
|
||||
return self.restricted
|
||||
>>>>>>> Stashed changes
|
||||
|
||||
def to_txt(self):
|
||||
lines = ["DICT=v3"]
|
||||
|
@ -108,7 +105,7 @@ class Chatlog(object):
|
|||
def from_txt(text):
|
||||
lines = text.splitlines()
|
||||
#print("Line 4=" + lines[4])
|
||||
print("Line 0=" + parse_line(lines[0]))
|
||||
print("-- Loaded " + parse_line(lines[0]) + ".")
|
||||
if(parse_line(lines[0]) == "v3"):
|
||||
new_log = Chatlog(parse_line(lines[1]), parse_line(lines[2]), parse_line(lines[3]), None, int(parse_line(lines[4])), float(parse_line(lines[5])), (parse_line(lines[6]) == 'True'))
|
||||
new_log.count = int(parse_line(lines[7]))
|
||||
|
|
13
velasco.py
13
velasco.py
|
@ -41,8 +41,9 @@ def wake(bot):
|
|||
|
||||
for c in chatlogs:
|
||||
try:
|
||||
print("Waking up on chat {}.".format(c))
|
||||
if WAKEUP:
|
||||
send_message(bot, update, "Good morning. I just woke up")
|
||||
bot.sendMessage(c, "Good morning. I just woke up")
|
||||
except:
|
||||
pass
|
||||
#del chatlogs[c]
|
||||
|
@ -128,7 +129,7 @@ def read(bot, update):
|
|||
chatlog.add_replyable(update.message.message_id)
|
||||
|
||||
replied = update.message.reply_to_message
|
||||
reply_text = update.message.text.casefold()
|
||||
reply_text = update.message.text.casefold() if update.message.text else ""
|
||||
to_reply = ((replied is not None) and (replied.from_user.name == "@velascobot")) or ("@velascobot" in reply_text) or ("velasco" in reply_text and "@velasco" not in reply_text)
|
||||
|
||||
if to_reply and chatlog.answering(random.random()):
|
||||
|
@ -186,10 +187,10 @@ def speak(bot, update):
|
|||
savechat(chatlog)
|
||||
chatlogs[chatlog.id] = chatlog
|
||||
|
||||
def send_message(bot, update, msg, reply_id):
|
||||
def send_message(bot, update, msg, reply_id=None):
|
||||
words = msg.split()
|
||||
if words[0] == STICKER_TAG:
|
||||
if is_reply:
|
||||
if reply_id is not None:
|
||||
update.message.reply_sticker(words[1])
|
||||
else:
|
||||
bot.sendSticker(update.message.chat_id, words[1])
|
||||
|
@ -310,11 +311,11 @@ def stop(bot, update):
|
|||
print("I got blocked by user " + chatlog.id)
|
||||
|
||||
def main():
|
||||
global ADMIN_ID
|
||||
global ADMIN_ID, WAKEUP
|
||||
parser = argparse.ArgumentParser(description='A Telegram markov bot.')
|
||||
parser.add_argument('token', metavar='TOKEN', help='The Bot Token to work with the Telegram Bot API')
|
||||
parser.add_argument('admin_id', metavar='ADMIN_ID', type=int, help='The ID of the Telegram user that manages this bot')
|
||||
parser.add_argument('-w', '--wakeup', metavar='WAKEUP_MSG', action='store_true', help='Flag that makes the bot send a first message to all chats during wake up.')
|
||||
parser.add_argument('-w', '--wakeup', action='store_true', help='Flag that makes the bot send a first message to all chats during wake up.')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
|
Loading…
Reference in a new issue