diff --git a/QuIRC.py b/QuIRC.py index 3d2cc16..61b599e 100644 --- a/QuIRC.py +++ b/QuIRC.py @@ -86,7 +86,7 @@ def run_once(self): print(logline) logfile.close() print('Closed logs file') - event_handler(self, packet.arguments[0], packet.prefix.split("!")[0], packet.arguments[1]) + event_handler(self, packet.arguments[0], packet.prefix, packet.arguments[1]) else: for event_handler in list(self.on_private_message): print('Found Private message') @@ -173,7 +173,7 @@ def send_message(self, to, message): ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') print('Got timestamp') - logline = '\n [' + to + '] @ ' + st +' -' + botnick + ' : ' + message + logline = '\n [' + str(to) + '] @ ' + str(st) +' -' + str(botnick) + ' : ' + str(message) logline = str(logline) logfile.write(logline) print('Logged message') @@ -294,10 +294,10 @@ def set_nick(self, nick): self.nick = nick self.send_line("NICK {}".format(nick)) - def send_user_packet(self, username): + def send_user_packet(self, username, realname): #Sends a user packet. This should be sent after your nickname. It is #displayed on clients when they view your details and look at "Real #Name". - self.send_line("USER {} 0 * :{}".format(username, username)) + self.send_line("USER {} 0 * :{}".format(username, realname)) diff --git a/README.md b/README.md index 733e035..226c7ca 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,4 @@ QuIRC is line of socket code. * Includes logging and terminal output plus built in weather bots, greetings bots, ping pong bots and URL title bots -[![Visit our IRC channel](https://kiwiirc.com/buttons/chat.freenode.net/#quirc.png)](https://kiwiirc.com/client/chat.freenode.net/?nick=quirc?##quirc) to talk to users and developers or email quircbot@gmail.com +[![Visit our IRC channel](https://kiwiirc.com/buttons/chat.freenode.net/#quirc.png)](https://kiwiirc.com/client/chat.freenode.net/?nick=quirc?#quirc) to talk to users and developers or email quircbot@gmail.com diff --git a/bot.py b/bot.py index c7e3ffc..0ec87b8 100644 --- a/bot.py +++ b/bot.py @@ -6,6 +6,8 @@ import random topic = '' #channel topic for use in channels where quotebot runs nick = 'quirctest123' +username = 'quirc' +realname = 'realname' bot = QuIRC.IRCConnection() lastgreeter = '' greetings = [ @@ -13,11 +15,12 @@ "Hi {}!", "Hello there {}!", "Hi there {}!", - "Hey {}!" -] + "Hey {}!"] owapikey = '' #place an api key for open weather map here admins = ['freenode-staff', 'freenode-staff'] + ##FUNCTION FLAGS - SET TO 1 TO ENABLE + greetingsbot = 1 weatherbot = 0 linkbot = 1 @@ -27,10 +30,13 @@ cashortbot = 1 nspassword = '' + def getinfo(): print('loadingconfig') global topic global nick + global username + global realname global greetings global greetingsbot global weatherbot @@ -50,6 +56,10 @@ def getinfo(): topic = setting[1] if setting[0] == 'nick': nick = setting[1] + if setting[0] == 'username': + username = setting[1] + if setting[0] == 'realname': + realname = setting[1] if setting[0] == 'greetings': greetings = setting[1].split(',') if setting[0] == 'greetingsbot': @@ -76,7 +86,7 @@ def getinfo(): def on_connect(bot): bot.set_nick(nick) - bot.send_user_packet(nick) + bot.send_user_packet(nick,realname) def on_welcome(bot): global nspassword @@ -85,7 +95,13 @@ def on_welcome(bot): time.sleep(10) bot.join_channel('#channel') print('Joined channels') -def on_message(bot, channel, sender, message): + +def on_message( + bot, + channel, + sender, + message + ): global topic global nick global lastgreeter @@ -99,29 +115,30 @@ def on_message(bot, channel, sender, message): global cashortbot global admins global owapikey + sendernick = sender.split('!')[0] + senderhost = sender.split('@')[1] if "hi " in message.lower() and greetingsbot == 1 or "hello " in message.lower() and greetingsbot == 1: global lastgreeter if lastgreeter == sender: print('Greetingsbot failed as sender was same as last greeter') else: print('got greeting message') - greeting_message = random.choice(greetings).format(sender) + greeting_message = random.choice(greetings).format(sendernick) print('picked greeting: ' + greeting_message) bot.send_message(channel, greeting_message) print('Sent greeting') lastgreeter = sender - for message_part in message.split(): - if message_part.startswith('!opme') and senderhost in chanops: + if message.lower().startswith('!opme') and sendernick in admins: bot.send_line('MODE ' + channel + ' +o ' + sendernick) - if message_part().startswith('!deopme') and senderhost in chanops: + if message.lower().startswith('!deopme') and sendernick in admins: bot.send_line('MODE ' + channel + ' -o ' + sendernick) - if message_part().startswith('!kick') and senderhost in chanops: + if message.lower().startswith('!kick') and sendernick in admins: arg = message.split(' ') target = arg[1] bot.send_line('KICK ' + channel + ' ' + target) - if message_part.startswith("http://") and linkbot == 1 or message_part.startswith("https://") and linkbot == 1: + if message.lower().startswith("http://") and linkbot == 1 or message.lower().startswith("https://") and linkbot == 1: print('Found link') html = requests.get(message_part).text title_match = re.search("