From 41283143ac88f86b36263038931d41f8019b7f54 Mon Sep 17 00:00:00 2001 From: ninjanerdbgm Date: Sun, 21 Aug 2016 23:15:49 -0400 Subject: [PATCH] Bug fixes --- gr3ybot.py | 15 ++++++++++----- telebot.py | 16 +++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/gr3ybot.py b/gr3ybot.py index 33e2483..9a795c9 100644 --- a/gr3ybot.py +++ b/gr3ybot.py @@ -180,13 +180,11 @@ def addToSearchDb(nick,msg): q.rollback() def pingAll(fromuser, msg): - print "pingall reached" q = con.db.cursor() try: q.execute(""" SELECT * FROM TelegramIDs """) n = q.fetchall() for pinger in n: - print pinger sendPing(fromuser,pinger[0],msg) except: if LOGLEVEL >= 2: log("Couldn't send ping to everyone.") @@ -323,7 +321,7 @@ def sendPing(fromuser, touser, msg): pinger.sendPing(fromuser,touser,msg) return "Sent!" except: - return "Error" + return "i couldnt find you in the ping list. try doing the /addme command again" def getMessage(data): @@ -758,12 +756,13 @@ def main(joined): host = getHost(data) status = admins(nick, host) try: - msg = info[1].translate(None, "\t\r\n") + msg = " ".join(info[1:]).translate(None, "\t\r\n") except: send("what are you announcing idiot",getChannel(data)) continue if status == 1: try: + send("ok i did a real good announcement.",getChannel(data)) pingAll("The Greynoise Podcast",msg) if LOGLEVEL >= 1: log("{0} made an announcement.".format(nick)) except: @@ -1272,7 +1271,7 @@ def main(joined): if len(info) > 1 and info[1].strip('\r\n').lower() == 'ping' and TELEGRAM_ENABLED: privsend("%ping ",name) privsend("this sends a message to a specified user via telegram. telegram will notify a users phone when it receives a message.",name) - privsend("if you want to be able to be pinged, download the telegram app on your phone and send \"/addme {0}\" to @gr3ybot.",name) + privsend("if you want to be able to be pinged, download the telegram app on your phone and send \"/addme {0}\" to @gr3ybot.".format(getNick(data)),name) privsend("----------------------",name) privsend(" - someone in chat.",name) privsend(" - optional. can be any message.",name) @@ -1664,6 +1663,12 @@ def main(joined): touser = touser.translate(None, "\t\r\n") if touser.lower() == "me": touser = getNick(data) + q = con.db.cursor() + q.execute(""" SELECT * FROM TelegramIDs WHERE ircUser = ? """, (touser,)) + n = q.fetchall() + if len(n) == 0: + send("that user didnt set up no pings yet. yell at them when they come back.",getChannel(data)) + continue if special == 1: for thing in info[2:]: if thing[0] == "#": diff --git a/telebot.py b/telebot.py index 840837c..649c884 100644 --- a/telebot.py +++ b/telebot.py @@ -26,17 +26,23 @@ def addNewUser(self, msg=None): def userToDb(self, username, userid): q = self.con.db.cursor() - q.execute(""" - INSERT INTO TelegramIDs (ircUser,telegramId) VALUES (?, ?) """, (username,userid)) - self.con.db.commit() - self.bot.sendMessage(userid, "ok ive added you. youll now get pings") + q.execute(""" SELECT * FROM TelegramIDs WHERE ircUser = ? """, (username,)) + n = q.fetchall() + if len(n) > 0: + self.bot.sendMessage(userid, "youre already set up. dont worry about it pal.") + self.con.db.commit() + else: + q.execute(""" + INSERT INTO TelegramIDs (ircUser,telegramId) VALUES (?, ?) """, (username,userid)) + self.con.db.commit() + self.bot.sendMessage(userid, "ok ive added you. youll now get pings") def sendPing(self, fromuser, touser, msg): sql = self.con.db.cursor() n = sql.execute(""" SELECT * FROM TelegramIDs WHERE ircUser = ? """, (touser,)) user = n.fetchall() for person in user: - if fromuser == touser: self.bot.sendMessage(person[1], "hey {0}, here's your requested ping: {2}".format(touser,msg)) + if fromuser == touser: self.bot.sendMessage(person[1], "hey {0}, here's your requested ping: {1}".format(touser,msg)) elif fromuser == "The Greynoise Podcast": self.bot.sendMessage(person[1], "Announcement: {0}".format(msg)) else: self.bot.sendMessage(person[1], "hey {0}, {1} is asking for you in irc: {2}".format(touser,fromuser,msg)) self.con.db.commit()