def plugsong(self, args, msg): global not_logged try: if not_logged: if login(mail, passw)["status"] != "ok": pp("Failed logging to PlugDJ", "ERROR") return "Ошибка подключения к PlugDJ" else: not_logged = False if msg.chan not in plug_rooms: return "" else: join_room(plug_rooms[msg.chan]) state = room_state() except LoginError: not_logged = True pp("Failed logging to PlugDJ: csrf is None", "ERROR") return "Ошибка подключения к PlugDJ" except Exception as detail: not_logged = True pp("Failed logging to PlugDJ: %s" % detail, "ERROR") return "Ошибка подключения к PlugDJ" # print(json.dumps(state, sort_keys=True, indent=4, separators=(',', ': '))) if state["status"] != "ok": not_logged = True pp("Failed getting room state", "ERROR") return "Ошибка подключения к PlugDJ" if state["data"][0]["playback"]: seconds = state["data"][0]["playback"]["media"]["duration"] m, s = divmod(seconds, 60) h, m = divmod(m, 60) timestr = "%02d:%02d:%02d" % (h, m, s) if h else "%02d:%02d" % (m, s) resp = "Сейчас играет на PlugDJ: %s - %s [%s]" % ( state["data"][0]["playback"]["media"]["author"], state["data"][0]["playback"]["media"]["title"], timestr, ) djname = name_of_user(state["data"][0]["booth"]["currentDJ"]) if djname: resp += ". DJ: %s" % djname return resp else: return "В данный момент музыка на PlugDJ не играет"
def plugsong(self, args, msg): global not_logged try: if not_logged: if login(mail, passw)['status'] != 'ok': pp('Failed logging to PlugDJ', 'ERROR') return 'Ошибка подключения к PlugDJ' else: not_logged = False if msg.chan not in plug_rooms: return '' else: join_room(plug_rooms[msg.chan]) state = room_state() except LoginError: not_logged = True pp('Failed logging to PlugDJ: csrf is None', 'ERROR') return 'Ошибка подключения к PlugDJ' except Exception as detail: not_logged = True pp('Failed logging to PlugDJ: %s' % detail, 'ERROR') return 'Ошибка подключения к PlugDJ' #print(json.dumps(state, sort_keys=True, indent=4, separators=(',', ': '))) if state['status'] != 'ok': not_logged = True pp('Failed getting room state', 'ERROR') return 'Ошибка подключения к PlugDJ' if state['data'][0]['playback']: seconds = state['data'][0]['playback']['media']['duration'] m, s = divmod(seconds, 60) h, m = divmod(m, 60) timestr = '%02d:%02d:%02d' % (h, m, s) if h else '%02d:%02d' % (m, s) resp = 'Сейчас играет на PlugDJ: %s - %s [%s]' % ( state['data'][0]['playback']['media']['author'], state['data'][0]['playback']['media']['title'], timestr) djname = name_of_user(state['data'][0]['booth']['currentDJ']) if djname: resp += '. DJ: %s' % djname return resp else: return 'В данный момент музыка на PlugDJ не играет'
def run(self): irc = self.irc sock = self.socket config = self.config global higher, lower # Initialize reusable properties. timers = {'!farm': time(), 'first_bet': time(), 'bet_timer': 0} higher = lower = {} while True: time_since_collect = int(time() - timers['!farm']) timers['bet_timer'] = int(time() - timers['first_bet']) # Check for PING; reply with PONG. data = sock.recv(2048).rstrip() irc.check_for_ping(data) message_dict, channel, message, username = self.check_for_message( irc, data) # Check if 180 minutes has passed since start. if time_since_collect > 10800: irc.send_message(channel, '!farm') timers['!farm'] = time() # Wait until 170 seconds has passed to bet. if timers['bet_timer'] >= 160 \ and self.bet_dict.get('betting_started')\ and not self.bet_dict.get('bet_submitted'): self.bet_logic(channel) self.bet_dict['bet_submitted'] = True # Check if the script is still connected to IRC. if len(data) == 0: general.pp('Connection was lost, reconnecting...') sock = self.irc.get_irc_socket_object # Check if most recent data is a message from Twitch chat. if username: if username == 'xxsaltbotxx': # Message contains 'bet complete for'. timers = self.check_salty_message(message, timers) if username == config['username']: if config['log_messages']: general.ppi(channel, message, username) # Check if the message is a command (i.e. starts with "!{command}"). if commands.is_valid_command( message) or commands.is_valid_command( message.split(' ')[0]): command = message # Command is a function (i.e. command should execute a script in the /src/lib/commands/ directory). if commands.check_returns_function( command.split(' ')[0]): if commands.check_has_correct_args( command, command.split(' ')[0]): args = command.split(' ') del args[0] command = command.split(' ')[0] if commands.is_on_cooldown(command, channel): general.pbot( f'Command is on cooldown. ({command}) ({username})' f'({commands.get_cooldown_remaining(command, channel)}s remaining)', channel) else: # Command (function) is not on cooldown, so send a message to Twitch chat. general.pbot(f'({command}) ({username})', channel) result = commands.pass_to_function( command, args) if result: # Function returned a valid result. general.pbot(result, channel) irc.send_message(channel, result) commands.update_last_used( command, channel) # Command is not a function and has no arguments (i.e. a simple command with a simple response, # such as "!test"). else: if commands.is_on_cooldown(command, channel): general.pbot( f'Command is on cooldown. ({command}) ({username}) ' f'({commands.get_cooldown_remaining(command, channel)}s remaining)', channel) elif commands.check_has_return(command): # Command is not on cooldown, so send a message to Twitch chat. general.pbot(f'({command}) ({username})', channel) res = commands.get_return(command) general.pbot(res, channel) irc.send_message(channel, res) commands.update_last_used(command, channel)
# -*- coding: utf-8 -*- __author__ = 'Life' import json import random from src.lib.functions_general import pp filename = 'src/res/emoticons.txt' try: emotes = json.loads(open(filename).read()) emotes = [el['regex'] for el in emotes['emoticons'] if el['regex'].isalpha()] except Exception: pp('Ошибка при обработке файла смайлов (будут исп. несколько известных)', 'error') emotes = ['Kappa', 'Keepo', 'OpieOP', 'duDudu'] turned_on = { '#c_a_k_e': False, '#nastjanastja': False, '#adrenaline_life': False, '#a_o_w': False } allowed_users = ( 'a_o_w', 'adrenaline_life', 'c_a_k_e', 'nastjanastja' )
def run(self): irc = self.irc sock = self.socket config = self.config global higher, lower, betting_started, time_since_first_bet # Initialize reusable properties. totals = {'blue_amt': 0, 'blue_bets': 0, 'red_amt': 0, 'red_bets': 0} timers = {'!collect': time(), 'first_bet': time()} higher = lower = {} bet_complete = False betting_started = False time_since_first_bet = 0 while True: time_since_collect = int(time() - timers['!collect']) time_since_first_bet = int(time() - timers['first_bet']) # Check if 60 minutes has passed yet. if time_since_collect > 3600: irc.send_message(channel, '!collect') timers['!collect'] = time() # Wait until 170 seconds has passed to bet. if time_since_first_bet >= 170 and betting_started and not bet_complete: # Check which team is in the lead. blue = {'name': 'blue', 'amt': totals['blue_amt'], 'bets': totals['blue_bets']} red = {'name': 'red', 'amt': totals['red_amt'], 'bets': totals['red_bets']} if red['amt'] > blue['amt']: higher = red lower = blue else: higher = blue lower = red # Bet on the underdog. underdog = lower['name'] # Bet 1000 mushrooms bet = int(1000) # Send the message and record the bet. irc.send_message(channel, '!%s %s' % (underdog, bet)) print('Bet complete: !%s %s\n' % (underdog, bet)) bet_complete = True betting_started = False data = sock.recv(2048).rstrip() # Check if the script is still connected to IRC. if len(data) == 0: general.pp('Connection was lost, reconnecting...') sock = self.irc.get_irc_socket_object # Check for PING; reply with PONG. irc.check_for_ping(data) # Check if most recent data is a message from Twitch chat. if irc.check_for_message(data): message_dict = irc.get_message(data) channel = message_dict['channel'] message = message_dict['message'] username = message_dict['username'] ####################################### # Handle messages sent by other users # ####################################### if username != config['username']: # Message was sent by @xxsaltbotxx. if username == 'xxsaltbotxx': # Message contains 'bet complete for'. if 'Bet complete' in message: # This is the first bet of the game. if totals['blue_amt'] == 0 and totals['red_amt'] == 0: timers['first_bet'] = time() time_since_first_bet = 0 betting_started = True # Parse values from xxsaltbotxx's message. split = message.split(' - Bet complete for ')[1].split(', ') team = split[0].lower() # Team name. amt = int(split[1].split('.')[0]) # Bet amount. # Increment totals each time a user bets. if team == 'blue': totals['blue_amt'] += amt totals['blue_bets'] += 1 else: totals['red_amt'] += amt totals['red_bets'] += 1 print('Time since first bet: %s s' % time_since_first_bet) print('Blue: \t%s shrooms, %s bets' % ("{:,}".format(totals['blue_amt']), totals['blue_bets'])) print('Red: \t%s shrooms, %s bets\n' % ("{:,}".format(totals['red_amt']), totals['red_bets'])) # Message contains 'Betting has ended' or over 3 minutes has passed. if 'Betting has ended' in message or time_since_first_bet >= 210: if totals['blue_amt'] != 0 and totals['red_amt'] != 0: if 'name' not in lower: lower['name'] = 'UNKNOWN' # Set all globals back to zero. totals = {'blue_amt': 0, 'blue_bets': 0, 'red_amt': 0, 'red_bets': 0} timers['first_bet'] = 0 time_since_first_bet = 0 bet_complete = False betting_started = False print('Betting has ended\n') ######################################## # Handle messages sent by your account # ######################################## if username == config['username']: if config['log_messages']: general.ppi(channel, message, username) # Check if the message is a command (i.e. starts with "!{command}"). if commands.is_valid_command(message) or commands.is_valid_command(message.split(' ')[0]): command = message # Command is a function (i.e. command should execute a script in the /src/lib/commands/ directory). if commands.check_returns_function(command.split(' ')[0]): if commands.check_has_correct_args(command, command.split(' ')[0]): args = command.split(' ') del args[0] command = command.split(' ')[0] if commands.is_on_cooldown(command, channel): general.pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % (command, username, commands.get_cooldown_remaining(command, channel)), channel) else: # Command (function) is not on cooldown, so send a message to Twitch chat. general.pbot('(%s) (%s)' % (command, username), channel) result = commands.pass_to_function(command, args) if result: # Function returned a valid result. general.pbot(result, channel) irc.send_message(channel, result) commands.update_last_used(command, channel) # Command is not a function and has no arguments (i.e. a simple command with a simple response, such as "!test"). else: if commands.is_on_cooldown(command, channel): general.pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % (command, username, commands.get_cooldown_remaining(command, channel)), channel) elif commands.check_has_return(command): # Command is not on cooldown, so send a message to Twitch chat. general.pbot('(%s) (%s)' % (command, username), channel) res = commands.get_return(command) general.pbot(res, channel) irc.send_message(channel, res) commands.update_last_used(command, channel)
allowed = ('c_a_k_e', 'a_o_w', 'nastjanastja', 'adrenaline_life') say = ('/me > Рагнарос выходит на стол!', '/me > Рагнарос покидает доску!') required_ch = ( '#a_o_w', ) try: ragn_list = load_obj('ragnaros') except FileNotFoundError: ragn_list = [Ragnaros(x) for x in required_ch] except Exception: ragn_list = [Ragnaros(x) for x in required_ch] pp("Could not load ragnaros file", 'error') else: loaded_ragn = [x.name for x in ragn_list] for x in required_ch: if x not in loaded_ragn: ragn_list.append(Ragnaros(x)) del loaded_ragn for x in ragn_list: x.victims = dict() x.last_time_hit = time.time() def ragnaros(self, args, msg): ragn = [x for x in ragn_list if x.name == msg.chan] if not ragn: return ''