Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #57 from quirc-bot/version-beta-1.1
Browse files Browse the repository at this point in the history
Beta Version 1.1
  • Loading branch information
sario528 authored May 25, 2020
2 parents 50fd247 + 72fb4c6 commit 05b0d60
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
8 changes: 4 additions & 4 deletions QuIRC.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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))
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
[![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 [email protected]
45 changes: 29 additions & 16 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
import random
topic = '' #channel topic for use in channels where quotebot runs
nick = 'quirctest123'
username = 'quirc'
realname = 'realname'
bot = QuIRC.IRCConnection()
lastgreeter = ''
greetings = [
"Hello {}!",
"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
Expand All @@ -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
Expand All @@ -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':
Expand All @@ -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
Expand All @@ -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
Expand All @@ -99,40 +115,39 @@ 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("<title>(.*?)</title>", html)
print('Finding a title')
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')
Expand All @@ -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))
Expand Down
6 changes: 5 additions & 1 deletion install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions settings.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
nick;quirctest123;
username;quirc;
realname;realname;
nspassword;password;
topic;channeltopics;
greetings;hello {}!,Hi {}!,Hello there {}!, Hi there {}!,Hey {};
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
download_url = "",
keywords = ["irc"]
Expand Down

0 comments on commit 05b0d60

Please sign in to comment.