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("(.*?)", html) @@ -129,10 +146,8 @@ def on_message(bot, channel, sender, message): if title_match: print(title_match.group(1)) title = title_match.group(1) - title = title.encode("ascii", "replace") print(title) message = "Title of the URL by {}: {}".format(sender, title) - message = message.encode("ascii", "replace") print(message) bot.send_message(channel, message) print('Sent title') @@ -155,15 +170,13 @@ def on_message(bot, channel, sender, message): else: bot.send_message(channel, "Usage: !weather Istanbul") for message_part in message.split(): - if message_part.startswith("!pickquote") and quotebot == 1: + if message.lower() == '!pickquote' and quotebot == 1: print('Got !pickquote command') - numq = message.lower() - numq = numq[10:] - print('Picking from ' + str(numq)) quotelist = open('quotes.csv', 'r') print('Getting quotes') quotes = quotelist.read() quotes = quotes.split(',') + numq = len(quotes) print('Read quotes') numq = int(numq)-1 picked = random.randint(0,int(numq)) diff --git a/install.py b/install.py index 545799d..c0eec09 100644 --- a/install.py +++ b/install.py @@ -25,6 +25,8 @@ print('----') nick = input('What is your bot nick? ') nspassword = input('What is the bot\'s NickServ Password? ') +username = input('What is your bot user name? ') +realname = input('What is your bot real name? ') topic = input('What is the topic in the channel the bot runs in? ') print('For each gretting please add a {} where the nick of the sender should go') print('After each greeting, place a comma to seperate them') @@ -45,8 +47,10 @@ print('Your settings file will now be created') file = open('settings.csv', 'w+') content = '' -content = 'nick;'+str(nick)+',\n' +content = 'nick;'+str(nick)+';\n' content = str(content)+'nspassword;'+str(nspassword)+';\n' +content = str(content)+'username;'+str(username)+';\n' +content = str(content)+'realname;'+str(realname)+';\n' content = str(content)+'topic;'+str(topic)+';\n' content = str(content)+'greetings;'+str(greetings)+';\n' content = str(content)+'greetingsbot;'+str(greetingsbot)+';\n' diff --git a/settings.csv b/settings.csv index e4191bc..7f04049 100644 --- a/settings.csv +++ b/settings.csv @@ -1,4 +1,6 @@ nick;quirctest123; +username;quirc; +realname;realname; nspassword;password; topic;channeltopics; greetings;hello {}!,Hi {}!,Hello there {}!, Hi there {}!,Hey {}; diff --git a/setup.py b/setup.py index f0b5a57..a9c3534 100644 --- a/setup.py +++ b/setup.py @@ -2,9 +2,9 @@ setup( name = "QuIRC", py_modules = ["QuIRC"], - version = "BetaV1", + version = "BetaV1.1", description = "Quick auto-logging IRC Bot", - author = "RhinosF1", + author = "RhinosF1 & Sario528", author_email = "quircbot@gmail.com" download_url = "", keywords = ["irc"]