Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjanerdbgm committed Aug 22, 2016
1 parent 33ab288 commit 4128314
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
15 changes: 10 additions & 5 deletions gr3ybot.py
Expand Up @@ -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.")
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1272,7 +1271,7 @@ def main(joined):
if len(info) > 1 and info[1].strip('\r\n').lower() == 'ping' and TELEGRAM_ENABLED:
privsend("%ping <user> <message>",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("<user> - someone in chat.",name)
privsend("<message> - optional. can be any message.",name)
Expand Down Expand Up @@ -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] == "#":
Expand Down
16 changes: 11 additions & 5 deletions telebot.py
Expand Up @@ -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()
Expand Down

0 comments on commit 4128314

Please sign in to comment.