Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from ConfigParser import RawConfigParser as ConfParser
- from BeautifulSoup import BeautifulSoup
- from optparse import OptionParser
- from collections import deque
- from time import sleep, time, gmtime, strftime
- import ConfigParser
- import random
- import os
- import sys
- import socket
- import codecs
- from irc import *
- from select import select
- import urllib
- import imp
- import modules.fml
- import modules.meme
- import modules.bitly
- import modules.eightball
- import threading
- my = IRCbot()
- start = time()
- server = "localhost"
- port = 1026
- nickpass = "nope <3"
- operlogin = "services nope<3"
- channels = "#chat"
- version = "1.0.0"
- logchan = "#s"
- internets = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- internets.connect((server, port))
- game = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- game.connect((server, port))
- pseudo = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- pseudo.connect((server, port))
- logger = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- logger.connect((server, port))
- try:
- config = ConfigParser.RawConfigParser()
- config.readfp(codecs.open("config.ini", "r", "utf8"))
- except IOError as config:
- sys.exit()
- class ChannelList(list): # Subclass of list, so it inherits every method of list
- def clear(self): # clear all elements
- for x in range(len(self)):
- del self[0]
- def load(self, filename): # load from filename
- self.clear()
- f = open(filename, "r")
- for chan in f: # line by line
- self.append(chan)
- f.close()
- def save(self, filename): # save into file
- f = open(filename, "w")
- f.write("\n".join(self)) # newline seperated (UNIX-newline)
- f.close()
- internets_channels = ChannelList()
- internets_channels.load("internets.channels.txt")
- gameserv_channels = ChannelList()
- gameserv_channels.load("gameserv.channels.txt")
- pseudoserv_channels = ChannelList()
- pseudoserv_channels.load("pseudoserv.channels.txt")
- logger_channels = ChannelList()
- logger_channels.load("pylog.channels.txt")
- def internets_bot(sock):
- internets.send('NICK Internets\r\n')
- internets.send('USER python Internets Internets :[Internets %s]\r\n' % version)
- while 1:
- data = readline(sock)
- raw = parse(data)
- #print("[Internets] %s" % raw)
- if raw[0].lower() == "ping":
- internets.send("PONG {reply}\r\n".format(reply = raw[1]))
- if raw[0].lower().startswith("nickserv!"):
- if raw[1] == "NOTICE" and "This nickname is registered" in raw[3]:
- internets.send('PRIVMSG NickServ :identify %s \r\n' % nickpass)
- internets.send('OPER %s \r\n' % operlogin)
- internets.send('JOIN %s \r\n' % channels)
- for channel in internets_channels:
- internets.send('JOIN %s \r\n' % channel)
- if raw[1] == "PRIVMSG":
- my.sender = raw[0]
- my.nick = raw[0].split("!")[0]
- my.auth = data.split('@')[0][1:]
- if len(raw) > 3:
- if raw[3] == ".help":
- internets.send('NOTICE %s :Internets: .help internets - for internets commands.\r\n' % my.nick)
- continue
- if raw[3].lower() == ".help internets":
- internets.send('NOTICE %s :Welcome to [Internets, version %s] by Aha2Y. Here is a list of my commands.\r\n' % (my.nick, version))
- internets.send('NOTICE %s : .fml gets a randomrandom entry from fmylife.com\r\n' % my.nick)
- internets.send('NOTICE %s : .meme spews out a meme from automeme.net\r\n' % my.nick)
- internets.send('NOTICE %s : .slogan makes a slogan from your given phrase\r\n' % my.nick)
- internets.send('NOTICE %s : .shorten makes your long url short with bitly\r\n' % my.nick)
- if raw[3].startswith(".reload "):
- try:
- if config.get('staff', my.auth) == 'admin':
- if raw[3].split(" ", 1)[1] == "fml":
- imp.reload(modules.fml)
- internets.send('PRIVMSG %s :Reloaded FML module.\r\n' % raw[2])
- except ConfigParser.NoOptionError:
- continue
- if raw[3] == ".fml":
- q = modules.fml.get()
- internets.send('PRIVMSG %s :[fml/#%s] %s\r\n' % (raw[2], q.number, q.text))
- internets.send('PRIVMSG %s :%s - %s\r\n' % (raw[2], q.agree, q.disagree))
- if raw[3] == ".meme":
- q = modules.meme.get()
- internets.send('PRIVMSG %s :[Meme] %s\r\n' % (raw[2], q.meme))
- imp.reload(modules.meme)
- if raw[3].startswith(".slogan"):
- try:
- slogan_topic = raw[3].split(" ", 1)[1]
- slogan_url = urllib.urlopen("http://parsers.faux-bot.com/slogan/%s" % slogan_topic)
- slogansoup = BeautifulSoup(slogan_url)
- x = str(slogansoup)
- x = x.split()
- slogan = " ".join(x[1:]).strip("End Response:")
- internets.send('PRIVMSG %s :[SloganMaker] "%s"\r\n' % (raw[2], slogan))
- except:
- internets.send('NOTICE %s :Syntax: .slogan <url>\r\n' % my.nick)
- if raw[3].startswith(".shorten"):
- try:
- shorten = raw[3].split(" ", 1)[1]
- api = modules.bitly.Api(login='aha2y', apikey='R_68fd8f8405600aab706feecbc07ea066')
- short=api.shorten(shorten,{'history':1})
- internets.send('PRIVMSG %s :[Bitly] %s\r\n' % (raw[2], short))
- except:
- internets.send('NOTICE %s :Syntax: .shorten <url>\r\n' % my.nick)
- def game_bot(sock):
- game.send('NICK GameServ\r\n')
- game.send('USER python GameServ GameServ :[GameServ %s]\r\n' % version)
- while 1:
- data = readline(sock)
- raw = parse(data)
- #print("[Internets] %s" % raw)
- if raw[0].lower() == "ping":
- game.send("PONG {reply}\r\n".format(reply = raw[1]))
- if raw[0].lower().startswith("nickserv!"):
- if raw[1] == "NOTICE" and "This nickname is registered" in raw[3]:
- game.send('PRIVMSG NickServ :identify %s \r\n' % nickpass)
- game.send('OPER %s \r\n' % operlogin)
- game.send('JOIN %s \r\n' % channels)
- for channel in gameserv_channels:
- game.send('JOIN %s \r\n' % channel)
- if raw[1] == "PRIVMSG":
- my.sender = raw[0]
- my.nick = raw[0].split("!")[0]
- my.auth = data.split('@')[0][1:]
- if len(raw) > 3:
- if raw[3] == ".help":
- game.send('NOTICE %s :GameServ: .help gameserv - for gameserv commands.\r\n' % my.nick)
- continue
- if raw[3].lower() == ".help gameserv":
- game.send('NOTICE %s :Welcome to [GameServ, version %s] by Aha2Y. Here is a list of my commands.\r\n' % (my.nick, version))
- game.send('NOTICE %s : .8ball Ask the magical eightball something.\r\n' % my.nick)
- if raw[3].startswith(".reload "):
- try:
- if config.get('staff', my.auth) == 'admin':
- if raw[3].split(" ", 1)[1] == "fml":
- imp.reload(modules.fml)
- game.send('PRIVMSG %s :Reloaded FML module.\r\n' % raw[2])
- except ConfigParser.NoOptionError:
- continue
- if raw[3].startswith(".8ball"):
- try:
- question = raw[3].split(" ", 1)[1]
- q = modules.eightball.get()
- game.send('PRIVMSG %s :%s: %s\r\n' % (raw[2], my.nick, q.eightball))
- imp.reload(modules.eightball)
- except:
- game.send('NOTICE %s :Syntax: .8ball <question>\r\n' % my.nick)
- def pseudo_bot(sock):
- pseudo.send('NICK pseudoServ\r\n')
- pseudo.send('USER Python pseudoServ pseudoServ :[pseudoServ %s]\r\n' % version)
- while 1:
- data = readline(sock)
- raw = parse(data)
- print("[Psuedo] %s" % raw)
- if raw[0].lower() == "ping":
- pseudo.send("PONG {reply}\r\n".format(reply = raw[1]))
- if raw[0].lower().startswith("nickserv!"):
- if raw[1] == "NOTICE" and "This nickname is registered" in raw[3]:
- pseudo.send('PRIVMSG NickServ :identify %s \r\n' % nickpass)
- pseudo.send('OPER %s \r\n' % operlogin)
- pseudo.send('JOIN %s \r\n' % channels)
- for channel in pseudoserv_channels:
- pseudo.send('JOIN %s \r\n' % channel)
- if raw[1] == "PRIVMSG":
- my.sender = raw[0]
- my.nick = raw[0].split("!")[0]
- my.auth = data.split('@')[0][1:]
- if len(raw) > 3:
- if raw[3] == ".help":
- pseudo.send('NOTICE %s :pseudoServ: .help pseudoserv - for gameserv commands.\r\n' % my.nick)
- continue
- if raw[3].lower() == ".help gameserv":
- pseudo.send('NOTICE %s :Welcome to [pseudoServ, version %s] by Aha2Y. Here is a list of my commands.\r\n' % (my.nick, version))
- if raw[3].startswith(".assign "):
- if raw[2] == "#chat":
- text_split = raw[3].split(" ")
- bot = text_split[1].lower()
- chan = text_split[2]
- if bot == "internets":
- if chan:
- pseudo.send('PRIVMSG %s :Assigning %s to %s\r\n' % (raw[2], bot, chan))
- internets.send('JOIN %s \r\n' % chan)
- internets_channels.append(chan)
- internets_channels.save("internets.channels.txt")
- else:
- pseudo.send('PRIVMSG %s :Please enter a channel. kthx.\r\n' % (raw[2], chan))
- if bot == "gameserv":
- if chan:
- pseudo.send('PRIVMSG %s :Assigning %s to %s\r\n' % (raw[2], bot, chan))
- game.send('JOIN %s \r\n' % chan)
- gameserv_channels.append(chan)
- gameserv_channels.save("gameserv.channels.txt")
- else:
- pseudo.send('PRIVMSG %s :Please enter a channel. kthx.\r\n' % (raw[2], chan))
- else:
- pseudo.send('PRIVMSG %s :Bot %s does not exist.\r\n' % (raw[2], bot))
- if raw[3].startswith(".unassign "):
- if raw[2] == "#chat":
- text_split = raw[3].split(" ")
- bot = text_split[1].lower()
- chan = text_split[2]
- if bot == "internets":
- if chan:
- pseudo.send('PRIVMSG %s :Unassigning %s from %s\r\n' % (raw[2], bot, chan))
- internets.send('PART %s \r\n' % chan)
- channels.remove(chan)
- internets_channels.save("internets.channels.txt")
- else:
- pseudo.send('PRIVMSG %s :Please enter a channel. kthx.\r\n' % (raw[2], chan))
- if bot == "gameserv":
- if chan:
- pseudo.send('PRIVMSG %s :Unassigning %s from %s\r\n' % (raw[2], bot, chan))
- game.send('PART %s \r\n' % chan)
- channels.remove(chan)
- gameserv_channels.save("gameserv.channels.txt")
- else:
- pseudo.send('PRIVMSG %s :Please enter a channel. kthx.\r\n' % (raw[2], chan))
- else:
- pseudo.send('PRIVMSG %s :Bot %s does not exist.\r\n' % (raw[2], bot))
- if raw[3] == ".uptime":
- end = time()
- uptime = end - start
- pseudo.send('PRIVMSG %s :Services are running for %s \r\n' % (raw[2], duration_human(uptime)))
- if raw[3].startswith(".massjoin "):
- text_split = raw[3].split(" ")
- victim = text_split[1].lower()
- amount = int(text_split[2])
- count = 1
- pseudo.send('PRIVMSG %s :Massjoining %s to %s Channels.\r\n' % (raw[2], victim, amount))
- while count < amount:
- pseudo.send('SAJOIN %s #random%s\n' % (victim, int(count)))
- count = count+1
- def logger_bot(sock):
- logger.send('NICK PyLogger\r\n')
- logger.send('USER Python pseudoServ pseudoServ :[pseudoServ %s]\r\n' % version)
- while 1:
- data = readline(sock)
- raw = parse(data)
- #print("[Internets] %s" % raw)
- if raw[0].lower() == "ping":
- logger.send("PONG {reply}\r\n".format(reply = raw[1]))
- if raw[0].lower().startswith("nickserv!"):
- if raw[1] == "NOTICE" and "This nickname is registered" in raw[3]:
- logger.send('PRIVMSG NickServ :identify %s \r\n' % nickpass)
- logger.send('OPER %s \r\n' % operlogin)
- logger.send('JOIN %s \r\n' % channels)
- for channel in logger_channels:
- logger.send('JOIN %s \r\n' % channel)
- if raw[1] == "PRIVMSG":
- my.sender = raw[0]
- my.nick = raw[0].split("!")[0]
- my.auth = data.split('@')[0][1:]
- if len(raw) > 3:
- if raw[3] == ".help":
- logger.send('NOTICE %s :PyLog: .help pylog - for pylog commands.\r\n' % my.nick)
- internets_thread = threading.Thread(target = internets_bot, args = (internets, )) # Thread object
- internets_thread.start()
- game_thread = threading.Thread(target = game_bot, args = (game, )) # Thread object
- game_thread.start()
- pseudo_thread = threading.Thread(target = pseudo_bot, args = (pseudo, )) # Thread object
- pseudo_thread.start()
- logger_thread = threading.Thread(target = logger_bot, args = (logger, )) # Thread object
- logger_thread.start()
- internets_thread.join()
- game_thread.join()
- pseudo_thread.join()
- logger_thread.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement