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 False
|
||||||
return rand <= self.answer
|
return rand <= self.answer
|
||||||
|
|
||||||
<<<<<<< Updated upstream
|
|
||||||
def add_replyable(self, msg_id):
|
def add_replyable(self, msg_id):
|
||||||
self.replyables.append(msg_id)
|
self.replyables.append(msg_id)
|
||||||
|
|
||||||
|
@ -84,13 +83,11 @@ class Chatlog(object):
|
||||||
|
|
||||||
def get_replyable(self):
|
def get_replyable(self):
|
||||||
random.choice(self.replyables)
|
random.choice(self.replyables)
|
||||||
=======
|
|
||||||
def toggle_restrict(self):
|
def toggle_restrict(self):
|
||||||
self.restricted = (not self.restricted)
|
self.restricted = (not self.restricted)
|
||||||
|
|
||||||
def is_restricted(self):
|
def is_restricted(self):
|
||||||
return self.restricted
|
return self.restricted
|
||||||
>>>>>>> Stashed changes
|
|
||||||
|
|
||||||
def to_txt(self):
|
def to_txt(self):
|
||||||
lines = ["DICT=v3"]
|
lines = ["DICT=v3"]
|
||||||
|
@ -108,7 +105,7 @@ class Chatlog(object):
|
||||||
def from_txt(text):
|
def from_txt(text):
|
||||||
lines = text.splitlines()
|
lines = text.splitlines()
|
||||||
#print("Line 4=" + lines[4])
|
#print("Line 4=" + lines[4])
|
||||||
print("Line 0=" + parse_line(lines[0]))
|
print("-- Loaded " + parse_line(lines[0]) + ".")
|
||||||
if(parse_line(lines[0]) == "v3"):
|
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 = 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]))
|
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:
|
for c in chatlogs:
|
||||||
try:
|
try:
|
||||||
|
print("Waking up on chat {}.".format(c))
|
||||||
if WAKEUP:
|
if WAKEUP:
|
||||||
send_message(bot, update, "Good morning. I just woke up")
|
bot.sendMessage(c, "Good morning. I just woke up")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
#del chatlogs[c]
|
#del chatlogs[c]
|
||||||
|
@ -128,7 +129,7 @@ def read(bot, update):
|
||||||
chatlog.add_replyable(update.message.message_id)
|
chatlog.add_replyable(update.message.message_id)
|
||||||
|
|
||||||
replied = update.message.reply_to_message
|
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)
|
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()):
|
if to_reply and chatlog.answering(random.random()):
|
||||||
|
@ -186,10 +187,10 @@ def speak(bot, update):
|
||||||
savechat(chatlog)
|
savechat(chatlog)
|
||||||
chatlogs[chatlog.id] = 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()
|
words = msg.split()
|
||||||
if words[0] == STICKER_TAG:
|
if words[0] == STICKER_TAG:
|
||||||
if is_reply:
|
if reply_id is not None:
|
||||||
update.message.reply_sticker(words[1])
|
update.message.reply_sticker(words[1])
|
||||||
else:
|
else:
|
||||||
bot.sendSticker(update.message.chat_id, words[1])
|
bot.sendSticker(update.message.chat_id, words[1])
|
||||||
|
@ -310,11 +311,11 @@ def stop(bot, update):
|
||||||
print("I got blocked by user " + chatlog.id)
|
print("I got blocked by user " + chatlog.id)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global ADMIN_ID
|
global ADMIN_ID, WAKEUP
|
||||||
parser = argparse.ArgumentParser(description='A Telegram markov bot.')
|
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('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('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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue