Created
January 16, 2015 23:46
-
-
Save irl/1b6d59fd211b994236db to your computer and use it in GitHub Desktop.
BeamerBot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import some necessary libraries. | |
import socket, collections | |
lines = collections.deque(maxlen=10) | |
for x in range(0, 10): | |
lines.append("") | |
# Some basic variables used to configure the bot | |
server = "irc.freenode.net" # Server | |
channel = "#57n" # Channel | |
botnick = "BeamerBot" # Your bots nick | |
def ping(): # This is our first function! It will respond to server Pings. | |
ircsock.send("PONG :pingis\n") | |
def sendmsg(chan , msg): # This is the send message function, it simply sends messages to the channel. | |
ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n") | |
def joinchan(chan): # This function is used to join channels. | |
ircsock.send("JOIN "+ chan +"\n") | |
def hello(): # This function responds to a user that inputs "Hello Mybot" | |
ircsock.send("PRIVMSG "+ channel +" :Hello!\n") | |
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
ircsock.connect((server, 6667)) # Here we connect to the server using the port 6667 | |
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :57North Wiki Bot\n") # user authentication | |
ircsock.send("NICK "+ botnick +"\n") # here we actually assign the nick to the bot | |
beamersock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
beameraddr = ('localhost', 4444) | |
joinchan(channel) # Join the channel using the functions we previously defined | |
while 1: # Be careful with these! it might send you to an infinite loop | |
ircmsg = ircsock.recv(2048) # receive data from the server | |
ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks. | |
print(ircmsg) # Here we print what's coming from the server | |
if ircmsg.find(":Hello "+ botnick) != -1: # If we can find "Hello Mybot" it will call the function hello() | |
hello() | |
if ircmsg.find("PRIVMSG #57N :") != -1: | |
username = ircmsg[:ircmsg.find("!")] | |
lines.append(username + ": " + ircmsg[ircmsg.find("#57N :") + len("#57N :"):]) | |
lines_list = list(lines) | |
beamersock.sendto("synchronized/child1/set_line_one:" + lines_list[0], beameraddr) | |
beamersock.sendto("synchronized/child1/set_line_two:" + lines_list[1], beameraddr) | |
beamersock.sendto("synchronized/child1/set_line_three:" + lines_list[2], beameraddr) | |
beamersock.sendto("synchronized/child1/set_line_four:" + lines_list[3], beameraddr) | |
beamersock.sendto("synchronized/child1/set_line_five:" + lines_list[4], beameraddr) | |
beamersock.sendto("synchronized/child1/set_line_six:" + lines_list[5], beameraddr) | |
beamersock.sendto("synchronized/child1/set_line_seven:" + lines_list[6], beameraddr) | |
beamersock.sendto("synchronized/child1/set_line_eight:" + lines_list[7], beameraddr) | |
beamersock.sendto("synchronized/child1/set_line_nine:" + lines_list[8], beameraddr) | |
beamersock.sendto("synchronized/child1/set_line_ten:" + lines_list[9], beameraddr) | |
if ircmsg.find("PING :") != -1: # if the server pings us then we've got to respond! | |
ping() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gl.setup(973, 705) | |
font = resource.load_font("font.ttf") | |
line_one = "<unset>" | |
line_two = "<unset>" | |
line_three = "<unset>" | |
line_four = "<unset>" | |
line_five = "<unset>" | |
line_six = "<unset>" | |
line_seven = "<unset>" | |
line_eight = "<unset>" | |
line_nine = "<unset>" | |
line_ten = "<unset>" | |
util.data_mapper{ | |
["set_line_one"] = function(new_text) | |
line_one = new_text | |
end | |
} | |
util.data_mapper{ | |
["set_line_two"] = function(new_text) | |
line_two = new_text | |
end | |
} | |
util.data_mapper{ | |
["set_line_three"] = function(new_text) | |
line_three = new_text | |
end | |
} | |
util.data_mapper{ | |
["set_line_four"] = function(new_text) | |
line_four = new_text | |
end | |
} | |
util.data_mapper{ | |
["set_line_five"] = function(new_text) | |
line_five = new_text | |
end | |
} | |
util.data_mapper{ | |
["set_line_six"] = function(new_text) | |
line_six = new_text | |
end | |
} | |
util.data_mapper{ | |
["set_line_seven"] = function(new_text) | |
line_seven = new_text | |
end | |
} | |
util.data_mapper{ | |
["set_line_eight"] = function(new_text) | |
line_eight = new_text | |
end | |
} | |
util.data_mapper{ | |
["set_line_nine"] = function(new_text) | |
line_nine = new_text | |
end | |
} | |
util.data_mapper{ | |
["set_line_ten"] = function(new_text) | |
line_ten = new_text | |
end | |
} | |
print "Hello from node child1" | |
function node.render() | |
gl.clear(0.3, 0, 0, 1) | |
font:write(30, 050, "#57N", 70, 1, 1, 1, 1) | |
font:write(30, 130, "irc.57north.org.uk", 30, 1, 1, 1, 1) | |
font:write(30, 200, line_one, 20, 1, 1, 1, 1) | |
font:write(30, 250, line_two, 20, 1, 1, 1, 1) | |
font:write(30, 300, line_three, 20, 1, 1, 1, 1) | |
font:write(30, 350, line_four, 20, 1, 1, 1, 1) | |
font:write(30, 400, line_five, 20, 1, 1, 1, 1) | |
font:write(30, 450, line_six, 20, 1, 1, 1, 1) | |
font:write(30, 500, line_seven, 20, 1, 1, 1, 1) | |
font:write(30, 550, line_eight, 20, 1, 1, 1, 1) | |
font:write(30, 600, line_nine, 20, 1, 1, 1, 1) | |
font:write(30, 650, line_ten, 20, 1, 1, 1, 1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment