def start(self): broker = Broker(self.rxq, self.txq) broker.find_plugins() irc = Irc(self.rxq, self.txq) self.irc_p = Process(target=irc.start) self.broker_p = Process(target=broker.start) self.irc_p.start() self.broker_p.start() for input in settings.INPUTS: input_path = path.join(settings.INPUTS_DIR, "%s.py" % input) if path.isfile(input_path): module = load_source(input, input_path) p = Process(target=module.input, args=(self.rxq, )) self.inputs.append(p) p.start() else: # warning pass
def __init__(self): self.config_path = "config/" self.module_path = "modules/" self.configure() self.irc = Irc(self.nick, self.channel) # load modules here self.module_handler = ModuleHandler(self.module_path, self.irc) self.parser = Parser(self.irc, self.module_handler, self.module_path) # always load the following: self.module_handler.load_module("loader", delay=False, startup=True) self.module_handler.load_module("core", delay=False, startup=True) self.module_handler.load_module("rand", delay=False, startup=True) self.module_handler.load_module("cheese", delay=False, startup=True) self.module_handler.load_module("images", delay=False, startup=True) self.module_handler.load_module("stackoverflow", delay=False, startup=True) self.module_handler.load_module("mood", delay=False, startup=True) self.module_handler.load_module("wiki", delay=False, startup=True) self.module_handler.load_module("shorty", delay=False, startup=True) self.module_handler.load_module("numfact", delay=False, startup=True)
def on_connect(con): # This protocol is responsible by spawning # the event LOAD. It takes care of spawning a CLOSE # event when the connection is over. Stdout(con) # This protocol is responsible by installing a dump method # into the con instance. It takes care of sending everything # that goes through the dump method. Stdin(con) # This protocol is used to break the stream of data into chunks delimited # by '\r\n'. So, if the network sends 'data1\r\ndata2\r\ndata3\r\n' it will # spawns three times the event FOUND. It will carry 'data1', 'data2', 'data3'. Shrug(con) # This untwisted protocol is a tiny implementation of irc protocol. # It handles about 80% of the irc events. It is possible to be improved # and handle 100% of all irc events. Irc(con) # We want to print out on the screen all data that comes from the irc server. xmap(con, LOAD, lambda con, data: sys.stdout.write('%s\n' % data)) # When the connection is over we need to destroy the Spin instance. The # lose function takes care of doing that for us. xmap(con, CLOSE, lambda con, err: lose(con)) # When the event 'PRIVMSG' happens then we will have our handle # on_privmsg called. You could experiment other irc commands. xmap(con, 'PRIVMSG', on_privmsg) # When the irc server requires us to send back a PONG :server. xmap(con, 'PING', on_ping) # Our nick. con.dump('NICK %s\r\n' % NICK) con.dump('USER %s %s %s :%s\r\n' % (IRC_X, IRC_Y, IRC_Z, IRC_W)) # Finally, it joins the channel. con.dump('JOIN %s\r\n' % CHANNEL)
def main(): lines = open('config.yml').read() config = yaml.load(lines) twitch = config['twitch'] revlo = config['revlo'] irc = Irc(twitch) token = revlo['api_key'] reward_id = int(revlo['reward_id']) print("Press Ctrl+C to kill the bot") try: while True: songs = scan_song_redemptions(token, reward_id) request_songs_to_nightbot(irc, twitch, songs) songs = [] time.sleep(60) except KeyboardInterrupt: print("Leaving channel") finally: irc.leave(twitch['channel'])
def main(config): twitch = config['twitch'] irc = Irc(twitch) user = [] print("Press Ctrl+C to kill the bot") try: k = True challenger = ["", ""] points = 0 gap_time = time.time() while True: recv_msg = irc.get_socket() if (re.match(r'^[a-zA-Z0-9\.\_\-]+ .*$', str(recv_msg))): recv_arg = recv_msg.split(" ", 1) if (re.match(r'\!pk [a-zA-Z0-9\.\_\-]+', recv_arg[1]) and (k == True or (time.time() - gap_time) > 10)): args = recv_msg.split(" ", 2) point = get_userPoint(config['api']['JWT_token'], twitch['channel'], args[0]) if (point == 0): irc.send_message(twitch['channel'], "%s 您的戰鬥力不足!" % args[0]) time.sleep(10) else: users = get_userList(twitch['channel']) if (args[2].strip().lower() in users or args[2].strip() != args[0].strip()): irc.send_message( twitch['channel'], "%s 戰鬥力 %s 的 %s 向您發起挑戰,是否接受(y/n)?" % (args[2], point, args[0])) challenger[0] = args[0].strip() challenger[1] = args[2].strip() points = point k = False gap_time = time.time() else: irc.send_message( twitch['channel'], "%s 找不到使用者:%s" % (args[0], args[2])) time.sleep(10) elif (recv_arg[0].strip() == challenger[1] and recv_arg[1].strip().lower() == 'y'): point = get_userPoint(config['api']['JWT_token'], twitch['channel'], recv_arg[0].strip()) if (point == 0): irc.send_message("%s 您的戰鬥力不足!" % recv_arg[0]) k = True time.sleep(10) else: allpoint = points + point nums = random.randint(0, 101) if (nums <= math.ceil((points / allpoint) * 100)): change_userPoint(config['api']['JWT_token'], challenger[0], point * 0.2) change_userPoint(config['api']['JWT_token'], challenger[1], 0 - (point * 0.2)) irc.send_message( twitch['channel'], "%s 恭喜您獲勝,獲得 %d 戰鬥力" % (challenger[0], point * 0.2)) irc.send_message( twitch['channel'], "%s 戰鬥失敗,失去 %d 戰鬥力" % (challenger[1], point * 0.2)) else: change_userPoint(config['api']['JWT_token'], challenger[1], points * 0.2) change_userPoint(config['api']['JWT_token'], challenger[0], 0 - (points * 0.2)) irc.send_message( twitch['channel'], "%s 恭喜您獲勝,獲得 %d 戰鬥力" % (challenger[1], points * 0.2)) irc.send_message( twitch['channel'], "%s 戰鬥失敗,失去 %d 戰鬥力" % (challenger[0], points * 0.2)) k = True time.sleep(10) elif (recv_arg[0].strip() == challenger[1] and recv_arg[1].strip().lower() == 'n'): irc.send_message(twitch['channel'], "戰鬥發起失敗") k = True time.sleep(10) except KeyboardInterrupt: print("Leaving channel") finally: irc.leave(twitch['channel'])
log.setLevel(logging.INFO) logging.getLogger("github.Requester").setLevel(logging.WARNING) logging.getLogger("urllib3.connectionpool").setLevel(logging.WARNING) # Rename "sample_config" to "config" and fill details config = configparser.ConfigParser() config.read("config") config = config["settings"] c = Irc( config.get("host"), int(config.get("port")), config.get("nick"), config.get("password"), config.get("conn_password"), config.get("username"), config.get("realname"), config.get("channel"), config.get("github_token"), ) async def main(): await c.connect() async with trio.open_nursery() as nursery: log.debug("parent: spawning sender...") nursery.start_soon(c.sender) log.debug("parent: spawning receiver...") nursery.start_soon(c.receiver)
from irc import Irc from omegle import Omegle from pyborg import pyborg import pyborg as pyborgmodule import ConfigParser from datetime import datetime, date, time import threading from threading import Thread, Lock from Queue import Queue from time import sleep import traceback config = ConfigParser.RawConfigParser() omegle = Omegle() omegle_lock = Lock() irc = Irc() pyborg = pyborg() pyborg_queue = Queue() pyborg_on = False pyborg_waiting = False owner="riking" owner=owner.lower() class emptyclass: pass def main(): config.read('bot.cfg') omegle.on_connected += omegle_connected omegle.on_disconnected += omegle_disconnected
def do_command(self, line): """This is a call back for screen It executes the command the user typed SUPPORTED COMMANDS: /disconnect - Disconnects from server /reconnect - Reconnects to the last server connected to /connect <host> [port] - Connects to the server using client settings for nick, user, real /quit - Quits program /easter - Egg /raw <text> - Sends <text> to IRC server without processing /switch - Change the default target to which messages without a slash are sent NOTE: default target is changed on joining channel/using /msg manually /msg <recipient> <message> - Sends a message to recipient /list - Shows a list of available channels /names [channel] - Shows a list of names in the channel, or in the server if none given /whois <nickname> - Shows information about the user /nick <newnick> - Change your nickname /join #<channel> - Join channel /part #<channel> - Part channel /topic #<channel> - Get channel topic /set - see all the settings /set <setting> - see the value for one setting /set <setting> <value> - change a setting /help - see this help message """ if line == '': return None parsed_command = self.command_parser.parse_command(line) # Returns a tuple if parsed_command[0] == 'disconnect': if self.connected and self.irc.is_connected(): logging.info(f'[Client] User requested disconnect with message {parsed_command[1]}') self.irc.disconnect() self.connected = False self.reset_state() self.screen.put_line('>>Disconnected') else: self.screen.put_line('>>You are not connected') elif parsed_command[0] == 'reconnect': self.reset_state() if not self.connected: self.irc.nick = self.nick self.irc.user = self.user self.irc.real = self.real self.irc.connect() if not self.irc.is_connected(): self.screen.put_line('>>Connection not successful') self.connected = False else: self.connected = True else: self.screen.put_line('>>You are already connected') elif parsed_command[0] == 'connect': self.reset_state() if not self.connected: self.screen.put_line('>>Attemping to connect...') self.screen.put_line('>>Timeout is 30 seconds.') self.irc = Irc(parsed_command[1], parsed_command[2], self.nick, self.user, self.real, self.parse_messages, self.buffer) self.irc.connect() if not self.irc.is_connected(): self.screen.put_line('>>Connection not successful') self.connected = False else: self.connected = True logging.info('[Client] Successfully connected') else: self.screen.put_line('>>You are already connected') elif parsed_command[0] == 'quit': logging.info('[Client] User requested quit') if self.connected and self.irc.is_connected(): logging.info(f'[Client] User requested disconnect with message {parsed_command[1]}') self.irc.disconnect() self.connected = False self.quit_signal.set() # Signals to main thread to quit elif parsed_command[0] == 'easter': self.screen.put_line(">>egg") elif parsed_command[0] == 'raw': self.try_send_raw(parsed_command[1]) elif parsed_command[0] == 'switch': self.default_target = parsed_command[1] elif parsed_command[0] == 'msg': self.try_send_raw(f'PRIVMSG {parsed_command[1]} :{parsed_command[2]}') self.default_target = parsed_command[1] self.set_status() self.screen.put_line(f'-{parsed_command[1]}- <{self.nick}> {parsed_command[2]}') elif parsed_command[0] == 'list': self.try_send_raw(f'LIST') elif parsed_command[0] == 'whois': self.screen.put_line(f'*** WHOIS info for {parsed_command[1]} ***') self.try_send_raw(f'WHOIS {parsed_command[1]}') elif parsed_command[0] == 'names': if parsed_command[1] == '': self.try_send_raw(f'NAMES *') else: self.try_send_raw(f'NAMES {parsed_command[1]}') elif parsed_command[0] == 'nick': self.try_send_raw(f'NICK {parsed_command[1]}') elif parsed_command[0] == 'join': self.try_send_raw(f'JOIN {parsed_command[1]}') self.default_target = parsed_command[1] self.try_send_raw(f'TOPIC {parsed_command[1]}') elif parsed_command[0] == 'part': self.try_send_raw(f'PART {parsed_command[1]}') if parsed_command[1] == self.default_target: self.default_target = None elif parsed_command[0] == 'topic': self.try_send_raw(f'TOPIC {parsed_command[1]}') elif parsed_command[0] == 'no_slash': if self.default_target == None: self.screen.put_line('>>No default target set') else: self.try_send_raw(f'PRIVMSG {self.default_target} :{line}') self.screen.put_line(f'-{self.default_target}- <{self.nick}> {line}') elif parsed_command[0] == 'getset': if parsed_command[1] == 'all': strings = self.settings.get_all() for line in strings: self.screen.put_line('>>' + line) else: result = self.settings.get(parsed_command[1]) if result: self.screen.put_line(f'>>{parsed_command[1]}: {result}') else: self.screen.put_line(f'>>{parsed_command[1]}: No such setting') elif parsed_command[0] == 'setset': result = self.settings.put(parsed_command[1], parsed_command[2]) if result: self.screen.put_line(f'>>Set {parsed_command[1]} to {result}') # if we are not connected, reset state for settings to take effect if not self.irc: self.reset_state() else: self.screen.put_line(f'>>No such setting {parsed_command[1]}') elif parsed_command[0] == 'version': self.screen.put_line('*** wiggleVerse version 0.39 ***') self.screen.put_line('This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.') self.screen.put_line('This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.') self.screen.put_line('You should have received a copy of the GNU General Public License (as COPYING) along with this program. If not, see <https://www.gnu.org/licenses/>.') elif parsed_command[0] == 'help': if os.path.isfile('HELP'): self.screen.put_line('*** wiggleVerse help ***') with open('HELP') as f: for line in f.readlines(): self.screen.put_line(line) else: self.screen.put_line('>>HELP file missing! Check README.md') elif parsed_command[0] == 'error': self.screen.put_line('>>' + parsed_command[1]) else: self.screen.put_line(f'>>Unknown error parsing command: {line}') self.set_status()
#!/usr/bin/python2.6 from irc import Irc from ircLoader import IrcLoader from optparse import OptionParser ## Command line parser to enable raw output parser = OptionParser() parser.add_option("-r", "--raw", action="store_true", dest="raw", default=False, help="Print the raw IRC data instead of formatting it.") (options, args) = parser.parse_args() datloader = IrcLoader() irc = Irc(datloader, options) irc.startIrc()