Skip to content

Commit 0643c23

Browse files
committed
Tried to clean up the code a bit, and make it more readable.
1 parent d709036 commit 0643c23

File tree

3 files changed

+86
-63
lines changed

3 files changed

+86
-63
lines changed

actions.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,48 @@
3838
## OF, OR IN CONNECTION WITH THE WORK OR THE USE OF OR OTHER DEALINGS IN THE WORK.
3939
#
4040

41-
# import the files required for this to work
41+
42+
## Import the files required for this to work.
4243
import requests, wikipedia
4344
import urbandictionary as ud
4445
import mwaaa
4546
from HTMLParser import HTMLParser
4647
from imdbparser import IMDb
4748

48-
# define a list of commands
49+
50+
## Define a list of commands.
4951
commands = ["?song", "?wiki", "?bye", "?ud", "?/", "?imdb"]
5052
commands += list(mwaaa.reply.keys())
5153
commands += ["PRIVMSG "+mwaaa.nick, mwaaa.updateKey]
5254

55+
56+
5357
def act(c,msg,sender,mem):
54-
5558
with open('callLog', 'a') as f:
5659
f.write(sender+": "+c+"\n"+msg+"\n\n")
5760

5861
r = ""
5962

60-
#basic text response
63+
64+
## Basic text response.
6165
if c in mwaaa.reply:
6266
r = mwaaa.reply[c]
6367

64-
#song
68+
69+
## Song.
6570
elif c == "?song":
6671
try:
6772
req = requests.get("http://letty.tk:8000/rds-xml.xsl")
6873
h = HTMLParser()
6974
r = h.unescape(req.content[29:-9])
7075
if len(r) < 3:
7176
r = "I don't hear anything."
72-
7377
except:
7478
r = "not now " + sender
75-
#r = "This feature is disabled :("
79+
#r = "This feature is disabled :("
80+
7681

77-
#text replacement
82+
## Text replacement.
7883
elif c == "?/":
7984
if msg[-1] == '/':
8085
msg = msg[:-1]
@@ -105,7 +110,8 @@ def act(c,msg,sender,mem):
105110
except:
106111
r = "well that didn't work :/"
107112

108-
#urban dictionary
113+
114+
## Urban Dictionary.
109115
elif c == "?ud":
110116
query = msg[msg.find("?ud") + 4:].replace('"',"'")
111117
try:
@@ -115,7 +121,8 @@ def act(c,msg,sender,mem):
115121
except:
116122
r = "well that didn't work :/"
117123

118-
#wikipedia
124+
125+
## Wikipedia.
119126
elif c == "?wiki":
120127
query = msg[msg.find("?wiki") + 6:]
121128
try:
@@ -128,7 +135,8 @@ def act(c,msg,sender,mem):
128135
except wikipedia.exceptions.PageError as e2:
129136
r = "Didn't find anything"
130137

131-
#IMDb
138+
139+
## IMDb.
132140
elif c == "?imdb":
133141
imdb = IMDb()
134142
title = msg[msg.find("?imdb") + 6:]
@@ -143,18 +151,24 @@ def act(c,msg,sender,mem):
143151
r = movie.title+" ("+str(movie.year)+") -- "+movie.plot
144152
except:
145153
r = "something went wrong :/"
146-
147-
#bot driver ### this will need to be redone in llamabot.py
148-
# if c == "PRIVMSG "+mwaaa.nick and sender in mwaaa.admins:
149-
# r = msg[msg.find("PRIVMSG "+mwaaa.nick)+15:]
150-
# elif c == "PRIVMSG "+mwaaa.nick and msg.find("?say") != -1:
151-
# r = msg[msg.find("?say")+5:]
152-
153-
#quit
154+
155+
156+
"""
157+
## Bot driver.
158+
## This will need to be redone in llamabot.py
159+
if c == "PRIVMSG "+mwaaa.nick and sender in mwaaa.admins:
160+
r = msg[msg.find("PRIVMSG "+mwaaa.nick)+15:]
161+
elif c == "PRIVMSG "+mwaaa.nick and msg.find("?say") != -1:
162+
r = msg[msg.find("?say")+5:]
163+
164+
"""
165+
166+
167+
## Quit.
154168
if c == "?bye" and sender in mwaaa.admins:
155169
exit(0)
156-
157170
if c == mwaaa.updateKey:
158171
reload(mwaaa)
159172

160173
return r.encode('utf-8')
174+

llamabot.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,49 +39,54 @@
3939
#
4040

4141

42-
# import the required libraries/files for this to work
42+
## Import the required libraries/files for this to work.
4343
import re, socket, os
4444
from time import sleep
4545
import actions
4646
import mwaaa
4747
import details
4848

49-
# Connect to the internet, then to IRC(at freenode for now, but it can be changed to other servers)
49+
50+
## Connect to the internet, then to IRC (at freenode for now, but it can be changed to other servers).
5051
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
5152
sock.connect(("irc.freenode.net", 6667))
5253
sock.send("USER "+details.username+" 2 3 "+details.username+ "\n")
5354
sock.send("NICK "+details.nick+"\n")
5455

55-
# use mwaaa.secret to use the password from the mwaaa.py file.
56+
57+
## Use mwaaa.secret to use the password from the mwaaa.py file.
5658
sock.send("PRIVMSG NickServ :identify "+details.secret+" \n")
5759
sleep(30) # finish ident before joining channel
5860
sock.send("JOIN "+details.channel+"\n")
5961

60-
# instantiate message buffer
61-
msgMem = []
6262

63+
## Instantiate message buffer.
64+
msgMem = []
6365
while True:
6466
msg = sock.recv(2048)
6567
print(msg)
66-
msg = msg.strip("\n\r")
6768

69+
msg = msg.strip("\n\r")
6870
sender = msg[1:msg.find('!')]
69-
7071
mloc = msg.find("PRIVMSG "+details.channel)+len(details.channel)+10
7172
msgMem.append(sender +"??"+ msg[mloc:])
7273

7374
if len(msgMem) > 20:
7475
msgMem.pop(0)
75-
76-
# if you receive a /PING send a response
76+
77+
78+
## If you receive a /PING send a response.
7779
if msg.find("PING :") != -1:
7880
sock.send("PONG :pingis\n")
79-
# if you find the update key defined in mwaaa.py, print 'update complete' and reload actions.py and mwaaa.py
81+
82+
83+
## If you find the update key defined in mwaaa.py, print 'update complete' and reload actions.py and mwaaa.py
8084
if msg.find(mwaaa.updateKey) != -1:
8185
print("update complete")
8286
reload(actions)
8387
reload(mwaaa)
8488

89+
8590
for command in actions.commands:
8691
msgLow = msg.lower()
8792
if msgLow.find(command.lower()) != -1:

mwaaa.py

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,42 @@
3939
#
4040

4141

42-
# change all of these things:
4342

44-
nick = "pronk" # the nickname the bot uses
45-
username = "pronk" # the bot's username
46-
channel = "##llamas" # the channel it joins when you start the bot script
47-
secret = "notreallythis"
48-
updateKey = "?update" # the command for updating the bot
49-
admins = ["mikez"] # a list of admins for the bot, who can give commands
43+
## Change all of these things:
44+
nick = "pronk" # the nickname the bot uses
45+
username = "pronk" # the username the bot uses
46+
channel = "##llamas" # the channel the bot joins, when you start the bot script
47+
secret = "notreallythis" # -
48+
updateKey = "?update" # the command for updating the bot
49+
admins = ["mikez"] # the list of Admins for the bot, who can give commands
50+
51+
52+
53+
## The reply ["?foo"] list below, defines a list of replies for preset commands.
54+
## They can be used for comedic effect.
55+
reply = dict() # <--- create the reply dictionary
56+
reply["?duckgoose"] = "The coolest duck/goose hybrid around. He's so perfect, words can't describe his awesomeness."
57+
reply["?fChanX"] = "One young, vibrant and perfect llama. <3"
58+
reply["?GPenguin"] = "Being from Germany, he enjoys meeting all kinds of people on IRC"
59+
reply["?help"] = "You're on your own."
60+
reply["?Kremator"] = "Booo!"
61+
reply["?letty"] = "All hail letty, our llama queen. She's leet af."
62+
reply["?list"] = "?song ?wiki ?ud ?/old/new ?help"
63+
reply["?mikez"] = "My daddy! :)"
64+
reply["?more"] = "No! No more!"
65+
reply["?mwaaa"] = "That's llama speak."
66+
reply["?Nawab"] = "The cool and sometimes mischievious guy next door who likes C++ and tea."
67+
reply["?[n0mad]"] = "[n0mwaaad]"
68+
reply["?pebble"] = "o"
69+
reply["?pronk"] = "Who me? llamabot by mikellama, https://github.com/mikellama/ircbot-llama/"
70+
reply["?radio"] = "http://letty.tk"
71+
reply["?Roserin"] = "?Hm yes."
72+
reply["?shantaram3013"] = "The cliche Asian whiz kid/emotional teenager. Loves electrical engineering and hanging out on ##llamas."
73+
reply["?Taco"] = "Im yummy! Gobble me up in a hurry and go to taco heaven!"
74+
reply["?Time-Warp"] = "OH NOZ!"
75+
reply["?website"] = "http://llamas.haxed.net"
76+
reply["?welcome"] = "[Welcome to ##llamas] - \"Keep calm and be a llama!\" We generally talk about anything here, as long as we respect the wishes of the owner of this channel."
77+
reply["?wodencafe"] = "The Java master!"
78+
reply["?WSPR"] = "Weak Signal Propagation Reporter"
79+
reply["?Zerock"] = "Henlo. Please remember, Zerock is the leetest llama."
5080

51-
# the reply ["?foo"] list below defines a list of replies for preset commands that can be used for comedic effect
52-
reply = dict()
53-
reply["?duckgoose"] = "The coolest duck/goose hybrid around. He's so perfect, words can't describe his awesomeness."
54-
reply["?fChanX"] = "One young, vibrant and perfect llama. <3"
55-
reply["?GPenguin"] = "Being from Germany, he enjoys meeting all kinds of people on IRC"
56-
reply["?help"] = "You're on your own."
57-
reply["?Kremator"] = "Booo!"
58-
reply["?letty"] = "All hail letty, our llama queen. She's leet af."
59-
reply["?list"] = "?song ?wiki ?ud ?/old/new ?help"
60-
reply["?mikez"] = "My daddy! :)"
61-
reply["?more"] = "No! No more!"
62-
reply["?mwaaa"] = "That's llama speak."
63-
reply["?Nawab"] = "The cool and sometimes mischievious guy next door who likes C++ and tea."
64-
reply["?[n0mad]"] = "[n0mwaaad]"
65-
reply["?pebble"] = "o"
66-
reply["?pronk"] = "Who me? llamabot by mikellama, https://github.com/mikellama/ircbot-llama/"
67-
reply["?radio"] = "http://letty.tk"
68-
reply["?Roserin"] = "?Hm yes."
69-
reply["?shantaram3013"] = "The cliche Asian whiz kid/emotional teenager. Loves electrical engineering and hanging out on ##llamas."
70-
reply["?Taco"] = "Im yummy! Gobble me up in a hurry and go to taco heaven!"
71-
reply["?Time-Warp"] = "OH NOZ!"
72-
reply["?website"] = "http://llamas.haxed.net"
73-
reply["?welcome"] = "[Welcome to ##llamas] - \"Keep calm and be a llama!\" We generally talk about anything here, as long as we respect the wishes of the owner of this channel."
74-
reply["?wodencafe"] = "The Java master!"
75-
reply["?WSPR"] = "Weak Signal Propagation Reporter"
76-
reply["?Zerock"] = "Henlo. Please remember, Zerock is the leetest llama."

0 commit comments

Comments
 (0)