Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import httplib
- import io
- import re
- import os
- import sys
- import random
- Host = "irc.freenode.net"
- Channel = "#bahahaha"
- Nick = "omgnoes"
- Password = "hsdgfhkasdgfasdfasdfasdfhasdgf81t3495tg978t78t"
- Sender = ""
- Text = ""
- IRC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- LoggedIn = []
- def ToChannel(Message):
- IRC.send("PRIVMSG " + Channel + " :" + str(Message) + "\r\n")
- def ToServer(Message):
- IRC.send(Message)
- def UserExists(UserName):
- if Text.find(UserName) != -1:
- UserFile = file("IRC_ChannelUsers.txt", "r")
- Users = UserFile.read()
- if Users.find(UserName) != -1:
- return True
- else:
- return False
- def HostMask(UserName):
- MaskFile = file("IRC_ChannelHosts.txt", "r")
- Masks = MaskFile.read()
- if Masks.find(UserName) != -1:
- return True
- else:
- return False
- def UserLoggedIn(UserName):
- if LoggedIn.count(UserName) == 1:
- return True
- else:
- return False
- def Check(Message):
- if Text.find(Message) != -1:
- return True
- else:
- return False
- #Connect
- IRC.connect((Host, 6667))
- ToServer('USER py host servname : Python Bot\r\n')
- ToServer('NICK ' + str(Nick) + '\r\n')
- #Main Loop
- while 1:
- Text = IRC.recv(1024)
- Sender = Text[Text.find(':') : Text.find('!')].strip(':')
- if not Text:
- break
- #Server - stuff
- if Check('Message of the Day'):
- ToServer('JOIN '+ Channel +'\r\n')
- if Check('PING'):
- ToServer('PONG ' + Text.split() [1] + '\r\n')
- if Check('KICK'):
- Kicker = Sender
- ToServer('JOIN '+ Channel +'\r\n')
- ToServer('KICK '+ Channel + " " + Kicker + " do not kick me.\r\n")
- if Check('This nickname is registered'):
- ToServer("NS IDENTIFY " + str(Password) + "\r\n")
- if Check("-o " + Nick):
- ToServer("PRIVMSG ChanServ :op " + str(Channel) + " " + str(Nick) + "\r\n")
- #Engine design reasoning
- if Check(':!stl'):
- ToServer('KICK ' + Channel + ' ' + Sender + '\r\n')
- #Process inputs
- if Check(':!logout'):
- if UserLoggedIn(Sender) == True:
- UserT = Text.split(':!logout')
- UserN = UserT[1].strip()
- if UserLoggedIn(UserN) == True:
- ToChannel(UserN + " Succesfully logged out.")
- LoggedIn.remove(UserN)
- else:
- if UserExists(UserN):
- ToChannel(UserN + " is not logged in.")
- else:
- ToChannel(Sender + " You're not authorized to do this.")
- if Check(':!login'):
- if UserLoggedIn(Sender) == True:
- ToChannel(Sender + " You're already logged in.")
- else:
- if UserExists(Sender) == True:
- if HostMask(Text.split()[0]) == True:
- ToChannel(str(Sender) + " You've succesfully logged in.")
- LoggedIn.append(Sender)
- else:
- ToChannel("Host masks do not match login criteria.")
- ToChannel("Your mask: " + Text.split()[0])
- else:
- ToChannel(str(Sender) + " You're not special, you have no account.")
- if Check(':!logoutme'):
- if UserLoggedIn(Sender) == True:
- ToChannel(Sender + " Succesfully logged out.")
- LoggedIn.remove(Sender)
- else:
- if UserExists(Sender) != True:
- ToChannel(str(Sender) + " You have no account, how can you logout?")
- else:
- ToChannel(str(Sender) + " You're not logged in, how can you logout?")
- if Check(':!voice'):
- if UserExists(Sender) == True and UserLoggedIn(Sender) == True:
- voice = Text.split(':!voice')
- voices = voice[1].strip()
- ToServer('MODE '+ str(Channel) +' +v '+ str(voices) +'\r\n')
- else:
- ToChannel('You`re not authorized to do this.')
- if Check(':!devoice'):
- if UserExists(Sender) == True and UserLoggedIn(Sender) == True:
- devoice = Text.split(':!devoice')
- devoices = devoice[1].strip()
- ToServer('MODE '+ str(Channel) +' -v '+ str(devoices) +'\r\n')
- else:
- ToChannel(str(Sender) + "You're not authorized to do this.")
- if Check(':!kick'):
- if UserExists(Sender) == True and UserLoggedIn(Sender) == True:
- TKick = Text.split(':!kick')
- Kick = TKick[1].strip()
- if Kick != Nick:
- ToServer('KICK ' + str(Channel) + " " + str(Kick) + '\r\n')
- else:
- ToChannel(Sender + " I cannot kick myself.")
- else:
- ToChannel(str(Sender) + " You're not authorized to do this.")
- if Check(':!help'):
- HTemp = Text.split(':!help')
- Help = HTemp[1].strip()
- if Help == "voice":
- ToChannel("To voice a user - syntax [ !voice nick ]")
- if Help == "devoice":
- ToChannel("To devoice a user - syntax [ !devoice nick ]")
- if Help == "kick":
- ToChannel("To kick a user - syntax [ !kick nick ]")
- if Help == "login":
- ToChannel("To login - syntax [ !login ]")
- if Help == "logout":
- ToChannel("To logout - syntax [ !logout ]")
- if Help == "deop":
- ToChannel("To remove operator status from a user - syntax [ !deop nick ]")
- if Help == "op":
- ToChannel("To give operator status to a user - syntax [ !op nick ]")
- if Help == "roulette":
- ToChannel("Play a game of roulette - syntax [ !roulette ]")
- if Help == "":
- ToChannel("Commands[+], login, logout, voice, devoice, kick, roulette, deop, op "+
- "- For more specific information try help [command], example !help login ")
- if Check(':!deop'):
- if UserExists(Sender) == True and UserLoggedIn(Sender) == True:
- deop = Text.split(':!deop')
- deops = deop[1].strip()
- if deops != Nick:
- ToServer('MODE '+ str(Channel) +' -o '+ str(deops) +'\r\n')
- else:
- ToChannel('I cannot deop myself!')
- else:
- ToChannel('You`re not authorized to do this.')
- if Check(':!op'):
- if UserExists(Sender) == True and UserLoggedIn(Sender) == True:
- op = Text.split(':!op')
- ops = op[1].strip()
- ToServer('MODE '+ str(Channel) +' +o '+ str(ops) +'\r\n')
- else:
- ToChannel('You`re not authorized to do this.')
- if Check(':!opme'):
- if UserExists(Sender) == True and UserLoggedIn(Sender) == True:
- ToServer('MODE '+ str(Channel) +' +o '+ str(Sender) +'\r\n')
- else:
- ToChannel('You`re not authorized to do this.')
- if Check(':!deopme'):
- if UserExists(Sender) == True and UserLoggedIn(Sender) == True:
- ToServer('MODE '+ str(Channel) +' -o '+ str(Sender) +'\r\n')
- else:
- ToChannel('You`re not authorized to do this.')
- if Check(":!adduser"):
- if UserExists(Sender) == True and UserLoggedIn(Sender) == True:
- UserTemp = Text.split(":!adduser")
- UserData = UserTemp[1].strip()
- UserName = str(UserData[: UserData.find("~") ]).replace(" ", "")
- UserHost = str(UserData[ UserData.find("~") :]).replace(" ", "")
- if UserExists(UserName) != True and HostMask(":"+UserName+"!" + UserHost) != True:
- UserNFile = file("IRC_ChannelUsers.txt", "a")
- UserNFile.write(UserName)
- UserHFile = file("IRC_ChannelHosts.txt", "a")
- UserHFile.write(":" + UserName + "!" + UserHost)
- UserNFile.close()
- UserHFile.close()
- ToChannel("Added user: " + UserName + " to trusted users.")
- else:
- ToChannel("Cannot add user: " + UserName + " user already exists.")
- else:
- ToChannel('You`re not authorized to do this.')
- if Check(":!deluser"):
- ToChannel("Unimplemented.")
- if Check(":!commits") or Text.find("~CIA@") != -1:
- os.system('cd ~/Kill--Field-Engine/ && git shortlog -s -n > ../IRCBot/git.log')
- GitLog = open('git.log', 'r')
- for Author in GitLog:
- if(Author.find("unknown") == -1):
- ToChannel(str(str(Author).strip()).lstrip('0123456789').strip() + str(": ") + re.sub("\D", "", str(Author).strip()) + str(" Commits."))
- # check code for other commands that do not exist
- if Text.find(":!") != -1:
- if Text.find(":!login" ) == -1 and \
- Text.find(":!logout" ) == -1 and \
- Text.find(":!logoutme") == -1 and \
- Text.find(":!voice" ) == -1 and \
- Text.find(":!devoice" ) == -1 and \
- Text.find(":!kick" ) == -1 and \
- Text.find(":!help" ) == -1 and \
- Text.find(":!deop" ) == -1 and \
- Text.find(":!op" ) == -1 and \
- Text.find(":!opme" ) == -1 and \
- Text.find(":!deopme" ) == -1 and \
- Text.find(":!adduser" ) == -1 and \
- Text.find(":!stl" ) == -1 and \
- Text.find(":!deluser" ) == -1 and \
- Text.find(":!commits" ) == -1:
- ToChannel("Unrecognised command: " + str(Text.split(':!')[1].strip()))
- print(Text.strip())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement