Example #1
0
def treatsForAllTimer(channel, delta):
    if twitch.get_stream_status(channel):
        user_dict, all_users = twitch.get_dict_for_users(channel)
        try:
            modify_points_all_users_timer(all_users, delta)
        except:
            return "Twitch's backend is down. Treats can't be added in this state. Moderators should monitor http://twitchstatus.com/ for updates."
Example #2
0
def treatsForAll(channel, delta):
    user_dict, all_users = twitch.get_dict_for_users(channel)
    try:
        modify_points_all_users(all_users, delta)
        return "{0} treats for everyone!".format(delta)
    except:
        return "Twitch's backend is down. Treats can't be added in this state. Moderators should monitor http://twitchstatus.com/ for updates."
def treatsForAll(delta):
    if get_stream_status():
        user_dict, all_users = twitch.get_dict_for_users()
        try:
            modify_points_all_users(1)
            print "Treats added to " + str(all_users)
        except:
            return "Twitch's backend is down. Treats can't be added in this state. Moderators should monitor http://twitchstatus.com/ for updates."
def treatsForAll(delta):
    if get_stream_status():
        user_dict, all_users = twitch.get_dict_for_users()
        try:
            modify_points_all_users(1)
            print "Treats added to " + str(all_users)
        except:
            return "Twitch's backend is down. Treats can't be added in this state. Moderators should monitor http://twitchstatus.com/ for updates."
Example #5
0
 def return_custom_command(channel, message, username):
     chan = channel.lstrip("#")
     elements = get_custom_command_elements(
         chan, message[0])
     replacement_user = username
     if len(message) > 1:
         replacement_user = message[1]
     resp = elements[1].replace(
         "{}", replacement_user).replace("[]", str(elements[2] + 1))
     if elements[0] == "mod":
         user_dict, __ = get_dict_for_users()
         if username in user_dict["chatters"]["moderators"]:
             self.irc.send_message(channel, resp)
             increment_command_counter(chan, message[0])
             save_message(BOT_USER, channel, resp)
     elif elements[0] == "reg":
         self.irc.send_message(channel, resp)
         increment_command_counter(chan, message[0])
         save_message(BOT_USER, channel, resp)
Example #6
0
def treats(args):
    add_remove = args[0]
    delta_user = args[1].lower()
    try:
        delta = int(args[2])
    except:
        return "amount has to be a number, ya dingus!"
    if add_remove == "add":
        if delta_user == "all":
            user_dict, all_users = twitch.get_dict_for_users()
            modify_points_all_users(all_users, abs(delta))
        else:
            modify_user_points(delta_user, abs(delta))
    elif add_remove == "remove":
        delta *= -1
        modify_user_points(delta_user, abs(delta) * -1)
    elif add_remove == "set":
        set_user_points(delta_user, delta)
    return "{} treats for {}!".format(delta, delta_user)
Example #7
0
 def custom_command(channel, message, username, elements):
     db = Database()
     command = elements[3]
     chan = channel.lstrip("#")
     replacement_user = username
     if len(message) > 1:
         replacement_user = message[1]
     if elements[6] == "mod":
         user_dict, __ = get_dict_for_users()
         if username in user_dict["chatters"]["moderators"]:
             resp = elements[4].replace("{}", replacement_user).replace(
                 "[]", str(elements[5]))
             self.irc.send_message(channel, resp)
             db.increment_command(command, chan)
         else:
             resp = "This is a moderator-only command"
             self.irc.send_message(channel, resp)
     elif elements[6] == "reg":
         resp = elements[4].replace("{}", replacement_user).replace(
             "[]", str(elements[5]))
         self.irc.send_message(channel, resp)
         db.increment_command(command, chan)
Example #8
0
def treats(args):

    user_dict, all_users = twitch.get_dict_for_users()

    usage = "!treats (add/remove [username] [amount])"

    approved_list = [
        'curvyllama', 'peligrosocortez', 'singlerider', 'newyork_triforce', 'agathos1337','undurfuzz69','jazzofrazz']

    add_remove = args[0]
    delta_user = args[1].lower()

    try:
        delta = int(args[2])
    except:
        return "amount has to be a number, ya dingus!"

    mod_name = globals.CURRENT_USER

    if mod_name not in approved_list:
        return "Only " + ", ".join(approved_list) + " are allowed to do that!"
    
    elif add_remove == "add":
        
        if delta_user == "all":
            modify_points_all_users(all_users, delta)
        else:
            modify_user_points(delta_user, delta)
        
    elif add_remove == "remove":
        delta *= -1
        modify_user_points(delta_user, delta)
        
    elif add_remove == "set":
        set_user_points(delta_user, delta)

    return "{} treats for {}!".format(delta, delta_user)
Example #9
0
    def handleCommand(self, command, channel, username, message):
        # parse arguments
        # if command is space case then
        #   !foo bar baz
        # turns into
        #   command = "!foo", args=["bar baz"]
        # otherwise it turns into
        #   command = "!foo", args=["bar", "baz:]
        # print("Inputs:", command, channel, username, message)
        if command == message:
            args = []
            
            
        ######TEMPORARY COMMAND IGNORES FOR shedeviil_09
        
        elif command == message and command in commands.keys():
            print "Yes, it is in commands"
            
            
            
            
        else:
            args = [message[len(command)+1:]] # default to args = ["bar baz"]

        if not commands.check_is_space_case(command) and args:
            # if it's not space case, break the arg apart
            args = args[0].split(" ")

        # print("Command:", command, "args", args)

        # check cooldown.
        if commands.is_on_cooldown(command, channel):
            pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % (
                command, username, commands.get_cooldown_remaining(command, channel)),
                channel
            )
            return
        pbot('Command is valid and not on cooldown. (%s) (%s)' %
                (command, username) ,channel)


        # Check for and handle the simple non-command case.
        cmd_return = commands.get_return(command)
        if cmd_return != "command":
            # it's a return = "some message here" kind of function
            resp = '(%s) : %s' % (username, cmd_return)
            commands.update_last_used(command, channel)
            self.irc.send_message(channel, resp)
            return


        # if there's a required userleve, validate it.
        if commands.check_has_ul(username, command):
            user_dict, all_users = twitch.get_dict_for_users()
            if username not in user_dict["chatters"]["moderators"]:
                resp = '(%s) : %s' % (
                    username, "This is a moderator-only command!")
                pbot(resp, channel)
                self.irc.send_message(channel, resp)
                return

       

        result = commands.pass_to_function(command, args)
        commands.update_last_used(command, channel)

        pbot("Command %s(%s) had a result of %s" % (command, args, result), channel)
        if result:
            resp = '(%s) : %s' % (username, result)
            pbot(resp, channel)
            self.irc.send_message(channel, resp)
Example #10
0
def battle(args, **kwargs):
    position = int(args[0])
    opponent = args[1].lower().lstrip("@")
    all_users = []
    username = kwargs.get("username", "testuser")
    channel = kwargs.get("channel", "testchannel")
    user_dict, all_users = get_dict_for_users(channel)
    now = datetime.datetime.utcnow()
    cooldown_time = 3
    last_battle_time = get_last_battle(username)
    WHISPER = kwargs.get("WHISPER", False)
    if last_battle_time < now - timedelta(minutes=cooldown_time):
        if opponent in all_users or WHISPER is True:
            if opponent != username:
                available_positions, occupied_positions = find_open_party_positions(
                    opponent)
                if len(occupied_positions) > 0:
                    eligible_positions = []
                    attacker_stats = get_battle_stats(
                        username, position)
                    for spot in occupied_positions:
                        all_defender_stats = get_battle_stats(
                            opponent, int(spot[0]))
                        if attacker_stats[0] - all_defender_stats[0] < 5:
                            if attacker_stats[0] - \
                                    all_defender_stats[0] > -5:
                                eligible_positions.append(spot[0])
                    if len(eligible_positions) > 0:
                        random_opponent_position = random.choice(
                            eligible_positions)
                    else:
                        recommended_fighters = []
                        them = get_user_battle_info(opponent)
                        you = get_user_battle_info(username)
                        for __, defender in them:
                            for pos, attacker in you:
                                if attacker - defender < 5:
                                    if attacker - defender > - 5:
                                        recommended_fighters.append(pos)
                        if len(recommended_fighters) > 0:
                            return "You can only battle an opponent with a Pokemon within 5 levels of your attacker! Try using your position {}!".format(
                                random.choice(recommended_fighters))
                        else:
                            return "Either you are too high of a level or not high enough to battle anything {} has! Try someone else?".format(
                                opponent)
                    nickname_1, pokemon_type1_id_1, pokemon_type2_id_1, pokemon_name_1, pokemon_type1_1, pokemon_type2_1 = user_pokemon_types_summary(
                        username, position)
                    nickname_2, pokemon_type1_id_2, pokemon_type2_id_2, pokemon_name_2, pokemon_type1_2, pokemon_type2_2 = user_pokemon_types_summary(
                        opponent, random_opponent_position)
                    defender_stats = get_battle_stats(
                        opponent, random_opponent_position)
                    attacker_modifier = pokemon_type1_id_1
                    defender_modifier = pokemon_type1_id_2
                    attacker_multiplier = get_attacker_multiplier(
                        attacker_modifier, defender_modifier)
                    defender_multiplier = get_defender_multiplier(
                        attacker_modifier, defender_modifier)
                    total_attacker = sum(
                        attacker_stats[2:7]) * attacker_multiplier
                    total_defender = sum(
                        defender_stats[2:7]) * defender_multiplier
                    set_battle_timestamp(username, now)
                    if total_attacker == total_defender:
                        return username + "'s " + nickname_1 + \
                            " and " + opponent + "'s " + nickname_2 + " had a draw."
                    elif total_attacker > total_defender:
                        if attacker_stats[0] < 100:  # attacker's level
                            level_up_user_pokemon(
                                username, position)
                        add_win(username)
                        return username + "'s " + nickname_1 + \
                            " defeated " + opponent + "'s " + nickname_2 + "."
                    elif total_attacker < total_defender:
                        add_loss(username)
                        return username + "'s " + nickname_1 + \
                            " was defeated by " + opponent + "'s " + nickname_2 + "."
                else:
                    return opponent + " has nothing to battle with. Tell them to use !catch"
            else:
                return "You can't battle yourself."
        else:
            return "Your opponent must be in this channel."
    else:
        return "It takes " + str(cooldown_time) + \
            " minutes for your Pokemon to heal!"
def user_is_moderator(username):
    if username in get_dict_for_users()[0]["chatters"]["moderators"]:
        return True
    else:
        return False
Example #12
0
    def handle_command(self, command, channel, username, message):
        if command == message:
            args = []
        elif command == message and command in commands.keys(
        ):  # pragma: no cover
            pass
        else:
            args = [message[len(command) + 1:]]
        if not commands.check_is_space_case(command) and args:
            args = args[0].split(" ")
        if (command == "!join"
                or command == "!leave") and channel == "#" + BOT_USER:
            self.join_part(command.lstrip("!"), "#" + username)
        if commands.is_on_cooldown(command, channel):
            pbot(
                'Command is on cooldown. (%s) (%s) (%ss remaining)' %
                (command, username,
                 commands.get_cooldown_remaining(command, channel)), channel)
            self.IRC.send_whisper(
                username, "Sorry! " + command + " is on cooldown for " +
                str(commands.get_cooldown_remaining(command, channel)) +
                " more seconds in " + channel.lstrip("#") +
                ". Can I help you?")
            return
        if commands.check_has_user_cooldown(command):
            if commands.is_on_user_cooldown(command, channel, username):
                self.IRC.send_whisper(
                    username, "Slow down! Try " + command + " in " +
                    channel.lstrip("#") + " in another " + str(
                        commands.get_user_cooldown_remaining(
                            command, channel, username)) + " seconds or just \
ask me directly?")
                return
            commands.update_user_last_used(command, channel, username)
        if check_for_blacklist(username):
            return
        pbot(
            'Command is valid and not on cooldown. (%s) (%s)' %
            (command, username), channel)
        cmd_return = commands.get_return(command)
        if cmd_return != "command":
            resp = '(%s) : %s' % (username, cmd_return)
            commands.update_last_used(command, channel)
            self.IRC.send_message(channel, resp)
            return
        command_has_ul = commands.check_has_ul(username, command)
        if command_has_ul:
            user_data, __ = twitch.get_dict_for_users(channel)
            if command_has_ul == "superuser":
                if username == SUPERUSER:
                    return commands.pass_to_function(
                        command,
                        args,
                        username=username,
                        channel=channel.lstrip("#"))
                else:
                    return
            try:
                moderator = get_moderator(username, channel.lstrip("#"))
                if not moderator and username != SUPERUSER:
                    resp = '(%s) : %s' % (username,
                                          "This is a moderator-only command!")
                    pbot(resp, channel)
                    self.IRC.send_whisper(username, resp)
                    return
            except Exception as error:  # pragma: no cover
                with open("errors.txt", "a") as f:
                    error_message = "{0} | {1} : {2}\n{3}\n{4}".format(
                        username, channel, command, user_data, error)
                    f.write(error_message)
        approved_channels = [
            PRIMARY_CHANNEL, BOT_USER, SUPERUSER, TEST_USER, EXTRA_CHANNEL
        ]
        if channel.lstrip("#") not in approved_channels:
            prevented_list = [
                'songrequest', 'request', 'shots', 'donation', 'welcome',
                'rules', 'gt', 'llama', 'loyalty', 'uptime', 'highlight',
                'weather', 'treats', 'wins', 'subcount'
            ]
            if command.lstrip("!") in prevented_list:
                return
        result = commands.pass_to_function(command,
                                           args,
                                           username=username,
                                           channel=channel.lstrip("#"))
        commands.update_last_used(command, channel)
        if result:
            resp = '(%s) : %s' % (username, result)
            pbot(resp, channel)
            save_message(BOT_USER, channel, resp)  # pragma: no cover
            return resp[:350]
Example #13
0
def battle(args, **kwargs):
    position = int(args[0])
    opponent = args[1].lower().lstrip("@")
    all_users = []
    username = kwargs.get("username", "testuser")
    channel = kwargs.get("channel", "testchannel")
    user_dict, all_users = get_dict_for_users(channel)
    now = datetime.now()
    cooldown_time = 3
    last_battle_time = get_last_battle(username)
    WHISPER = kwargs.get("WHISPER", False)
    if last_battle_time < now - timedelta(minutes=cooldown_time):
        if opponent in all_users or WHISPER is True:
            if opponent != username:
                available_positions, occupied_positions = find_open_party_positions(
                    opponent)
                if len(occupied_positions) > 0:
                    eligible_positions = []
                    attacker_stats = get_battle_stats(
                        username, position)
                    for spot in occupied_positions:
                        all_defender_stats = get_battle_stats(
                            opponent, int(spot[0]))
                        if attacker_stats[0] - all_defender_stats[0] < 5:
                            if attacker_stats[0] - \
                                    all_defender_stats[0] > -5:
                                eligible_positions.append(spot[0])
                    if len(eligible_positions) > 0:
                        random_opponent_position = random.choice(
                            eligible_positions)
                    else:
                        recommended_fighters = []
                        them = get_user_battle_info(opponent)
                        you = get_user_battle_info(username)
                        for __, defender in them:
                            for pos, attacker in you:
                                if attacker - defender < 5:
                                    if attacker - defender > - 5:
                                        recommended_fighters.append(pos)
                        if len(recommended_fighters) > 0:
                            return "You can only battle an opponent with a Pokemon within 5 levels of your attacker! Try using your position {}!".format(
                                random.choice(recommended_fighters))
                        else:
                            return "Either you are too high of a level or not high enough to battle anything {} has! Try someone else?".format(
                                opponent)
                    nickname_1, pokemon_type1_id_1, pokemon_type2_id_1, pokemon_name_1, pokemon_type1_1, pokemon_type2_1 = user_pokemon_types_summary(
                        username, position)
                    nickname_2, pokemon_type1_id_2, pokemon_type2_id_2, pokemon_name_2, pokemon_type1_2, pokemon_type2_2 = user_pokemon_types_summary(
                        opponent, random_opponent_position)
                    defender_stats = get_battle_stats(
                        opponent, random_opponent_position)
                    attacker_modifier = pokemon_type1_id_1
                    defender_modifier = pokemon_type1_id_2
                    attacker_multiplier = get_attacker_multiplier(
                        attacker_modifier, defender_modifier)
                    defender_multiplier = get_defender_multiplier(
                        attacker_modifier, defender_modifier)
                    total_attacker = sum(
                        attacker_stats[2:7]) * attacker_multiplier
                    total_defender = sum(
                        defender_stats[2:7]) * defender_multiplier
                    set_battle_timestamp(username)
                    if total_attacker == total_defender:
                        return username + "'s " + nickname_1 + \
                            " and " + opponent + "'s " + nickname_2 + " had a draw."
                    elif total_attacker > total_defender:
                        if attacker_stats[0] < 100:  # attacker's level
                            level_up_user_pokemon(
                                username, position)
                        add_win(username)
                        return username + "'s " + nickname_1 + \
                            " defeated " + opponent + "'s " + nickname_2 + "."
                    elif total_attacker < total_defender:
                        add_loss(username)
                        return username + "'s " + nickname_1 + \
                            " was defeated by " + opponent + "'s " + nickname_2 + "."
                else:
                    return opponent + " has nothing to battle with. Tell them to use !catch"
            else:
                return "You can't battle yourself."
        else:
            return "Your opponent must be in this channel."
    else:
        return "It takes " + str(cooldown_time) + \
            " minutes for your Pokemon to heal!"
Example #14
0
    def handle_command(self, command, channel, username, message):
        db = Database()
        is_active = db.get_active_command(
            channel=channel.lstrip("#"), command=command)[0]
        if is_active == 0:
            return
        if command == message:
            args = []
        elif command == message and command in commands.keys():  # pragma: no cover
            pass
        else:
            args = [message[len(command) + 1:]]
        if not commands.check_is_space_case(command) and args:
            args = args[0].split(" ")
        if commands.is_on_cooldown(command, channel):
            pbot('Command is on cooldown. ({0}) ({1}) ({2}s remaining)'.format(
                command, username, commands.get_cooldown_remaining(
                    command, channel)), channel)
            self.whisper(
                username, channel,  "Sorry! " + command +
                " is on cooldown for " + str(
                    commands.get_cooldown_remaining(
                        command, channel)
                ) + " more seconds in " + channel.lstrip("#") +
                ". Can I help you?")
            return
        if commands.check_has_user_cooldown(command):
            if commands.is_on_user_cooldown(command, channel, username):
                self.whisper(
                    username, channel, "Slow down! Try " + command +
                    " in " + channel.lstrip("#") + " in another " + str(
                        commands.get_user_cooldown_remaining(
                            command, channel, username)) + " seconds or just \
ask me directly?")
                return
            commands.update_user_last_used(command, channel, username)
        cmd_return = commands.get_return(command)
        if cmd_return != "command":
            resp = '(%s) : %s' % (username, cmd_return)
            commands.update_last_used(command, channel)
            self.msg(channel, resp)
            return
        if commands.check_has_ul(username, command):
            user_data, __ = twitch.get_dict_for_users(channel)
            try:
                moderator = Database().get_moderator(username, channel.lstrip("#"))
                if not moderator and username != SUPERUSER:
                    resp = '(%s) : %s' % (
                        username, "This is a moderator-only command!")
                    pbot(resp, channel)
                    self.msg(channel, resp)
                    return
            except Exception as error:  # pragma: no cover
                with open("errors.txt", "a") as f:
                    error_message = "{0} | {1} : {2}\n{3}\n{4}".format(
                        username, channel, command, user_data, error)
                    f.write(error_message)
        result = commands.pass_to_function(
            command, args, username=username, channel=channel.lstrip("#"))
        commands.update_last_used(command, channel)
        if result:
            resp = '(%s) : %s' % (username, result)[:350]
            pbot(resp, channel)
            return resp
Example #15
0
    def handleCommand(self, command, channel, username, message):
        # parse arguments
        # if command is space case then
        #   !foo bar baz
        # turns into
        #   command = "!foo", args=["bar baz"]
        # otherwise it turns into
        #   command = "!foo", args=["bar", "baz:]
        # print("Inputs:", command, channel, username, message)
        if command == message:
            args = []

        ######TEMPORARY COMMAND IGNORES FOR shedeviil_09

        elif command == message and command in commands.keys():
            print "Yes, it is in commands"

        else:
            args = [message[len(command) + 1:]
                    ]  # default to args = ["bar baz"]

        if not commands.check_is_space_case(command) and args:
            # if it's not space case, break the arg apart
            args = args[0].split(" ")

        # print("Command:", command, "args", args)

        # check cooldown.
        if commands.is_on_cooldown(command, channel):
            pbot(
                'Command is on cooldown. (%s) (%s) (%ss remaining)' %
                (command, username,
                 commands.get_cooldown_remaining(command, channel)), channel)
            return
        pbot(
            'Command is valid and not on cooldown. (%s) (%s)' %
            (command, username), channel)

        # Check for and handle the simple non-command case.
        cmd_return = commands.get_return(command)
        if cmd_return != "command":
            # it's a return = "some message here" kind of function
            resp = '(%s) : %s' % (username, cmd_return)
            commands.update_last_used(command, channel)
            self.irc.send_message(channel, resp)
            return

        # if there's a required userleve, validate it.
        if commands.check_has_ul(username, command):
            user_dict, all_users = twitch.get_dict_for_users()
            if username not in user_dict["chatters"]["moderators"]:
                resp = '(%s) : %s' % (username,
                                      "This is a moderator-only command!")
                pbot(resp, channel)
                self.irc.send_message(channel, resp)
                return

        result = commands.pass_to_function(command, args)
        commands.update_last_used(command, channel)

        pbot("Command %s(%s) had a result of %s" % (command, args, result),
             channel)
        if result:
            resp = '(%s) : %s' % (username, result)
            pbot(resp, channel)
            self.irc.send_message(channel, resp)
Example #16
0
def winner(**kwargs):
    user_dict, all_users = twitch.get_dict_for_users()
    stream_winner = random.choice(all_users)
    random.shuffle(all_users)
    return stream_winner
Example #17
0
 def handleCommand(self, command, channel, username, message):
     # parse arguments
     # if command is space case then
     #   !foo bar baz
     # turns into
     #   command = "!foo", args=["bar baz"]
     # otherwise it turns into
     #   command = "!foo", args=["bar", "baz:]
     # print("Inputs:", command, channel, username, message)
     if command == message:
         args = []
     elif command == message and command in commands.keys():
         pass
     else:
         # default to args = ["bar baz"]
         args = [message[len(command) + 1:]]
     if not commands.check_is_space_case(command) and args:
         # if it's not space case, break the arg apart
         args = args[0].split(" ")
     if commands.is_on_cooldown(command, channel):
         pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % (
             command, username, commands.get_cooldown_remaining(
                 command, channel)), channel)
         return
     if commands.check_has_user_cooldown(command):
         if commands.is_on_user_cooldown(command, channel, username):
             return
         commands.update_user_last_used(command, channel, username)
     pbot('Command is valid and not on cooldown. (%s) (%s)' %
          (command, username), channel)
     # Check for and handle the simple non-command case.
     cmd_return = commands.get_return(command)
     if cmd_return != "command":
         # it's a return = "some message here" kind of function
         resp = '(%s) : %s' % (username, cmd_return)
         commands.update_last_used(command, channel)
         self.irc.send_message(channel, resp)
         return
     # if there's a required userlevel, validate it.
     if commands.check_has_ul(username, command):
         user_data, __ = twitch.get_dict_for_users(channel)
         try:
             if username not in user_data["chatters"]["moderators"]:
                 if username != SUPERUSER:
                     resp = '(%s) : %s' % (
                         username, "This is a moderator-only command!")
                     pbot(resp, channel)
                     self.irc.send_message(channel, resp)
                     return
         except Exception as error:
             with open("errors.txt", "a") as f:
                 error_message = "{0} | {1} : {2}\n{3}\n{4}".format(
                     username, channel, command, user_data, error)
                 f.write(error_message)
     approved_channels = [PRIMARY_CHANNEL, BOT_USER, SUPERUSER, TEST_USER]
     if globals.CURRENT_CHANNEL not in approved_channels:
         print globals.CURRENT_CHANNEL
         prevented_list = ['songrequest', 'request', 'shots', 'donation',
                           'welcome', 'rules', 'poll', 'vote', 'gt',
                           'llama', 'loyalty', 'uptime', 'highlight',
                           'weather', 'poll', 'treats', 'vote']
         if command.lstrip("!") in prevented_list:
             return
     result = commands.pass_to_function(command, args)
     commands.update_last_used(command, channel)
     if result:
         resp = '(%s) : %s' % (username, result)
         pbot(resp, channel)
         self.irc.send_message(channel, resp)
         if channel == "#" + PRIMARY_CHANNEL:
             write_to_log(channel, "[BOT]", resp)
         save_message(BOT_USER, channel, resp)
Example #18
0
 def handleCommand(self, command, channel, username, message):
     # parse arguments
     # if command is space case then
     #   !foo bar baz
     # turns into
     #   command = "!foo", args=["bar baz"]
     # otherwise it turns into
     #   command = "!foo", args=["bar", "baz"]
     # print("Inputs:", command, channel, username, message)
     if command == message:
         args = []
     else:
         # default to args = ["bar baz"]
         args = [message[len(command) + 1:]]
     if not commands.check_is_space_case(command) and args:
         # if it's not space case, break the arg apart
         args = args[0].split(" ")
     if commands.is_on_cooldown(command, channel):
         pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % (
             command, username, commands.get_cooldown_remaining(
                 command, channel)), channel)
         return
     if commands.check_has_user_cooldown(command):
         if commands.is_on_user_cooldown(command, channel, username):
             resp = "Sorry! You've got " + str(
                 commands.get_user_cooldown_remaining(
                     command, channel, username)) + \
                 " seconds before you can do that again, " + username + "!"
             self.irc.send_message(channel, resp)
             return
         commands.update_user_last_used(command, channel, username)
     pbot('Command is valid and not on cooldown. (%s) (%s)' %
          (command, username), channel)
     # Check for and handle the simple non-command case.
     cmd_return = commands.get_return(command)
     if cmd_return != "command":
         # it's a return = "some message here" kind of function
         resp = '(%s) : %s' % (username, cmd_return)
         commands.update_last_used(command, channel)
         self.irc.send_message(channel, resp)
         return
     # if there's a required userlevel, validate it.
     if commands.check_has_ul(username, command):
         user_data, __ = twitch.get_dict_for_users(channel)
         try:
             if username not in user_data["chatters"]["moderators"]:
                 if username != TEST_USER:
                     resp = '(%s) : %s' % (
                         username, "This is a moderator-only command!")
                     pbot(resp, channel)
                     self.irc.send_message(channel, resp)
                     return
         except Exception as error:
             with open("errors.txt", "a") as f:
                 error_message = "{0} | {1} : {2}\n{3}\n{4}".format(
                     username, channel, command, user_data, error)
                 f.write(error_message)
     approved_channels = [STREAM_USER, BOT_USER, TEST_USER]
     if globals.CURRENT_CHANNEL not in approved_channels:
         prevented_list = []
         if command.lstrip("!") in prevented_list:
             return
     result = commands.pass_to_function(command, args)
     commands.update_last_used(command, channel)
     if result:
         resp = '/w %s %s' % (username, result)
         pbot(resp, channel)
         self.irc.send_message(channel, resp)
Example #19
0
def winner():
    user_dict, all_users = twitch.get_dict_for_users()
    stream_winner = random.choice(all_users)
    random.shuffle(all_users)
    return stream_winner
Example #20
0
def user_is_moderator(username):
    if username in get_dict_for_users()[0]["chatters"]["moderators"]:
        return True
    else:
        return False