コード例 #1
0
ファイル: custom_commands.py プロジェクト: singlerider/docbot
def edit(
        channel, username, trigger, response, user_level, time_interval,
        times_used):
    channel = channel.lstrip("#")
    if commands.get(trigger) is not None:
        return "{0} can't be edited in {1}!".format(
            trigger, channel)
    with db.atomic():
        User.get_or_create(username=username)
        Channel.get_or_create(channel=channel)
        try:
            # attempts to retrieve a user object
            Command.get(
                channel=Channel.get(channel=channel).id,
                trigger=trigger)
            Command.update.(
                username=User.get(username=username).id,
                trigger=trigger, response=response, user_level=user_level,
                time_interval=time_interval
                ).where(
                    channel=Channel.get(channel=channel).id,
                    trigger=trigger
                ).execute()
        except Command.DoesNotExist:
            return "{0} not found in {1}!".format(trigger, channel)
コード例 #2
0
ファイル: points.py プロジェクト: singlerider/docbot
def modify_points(channel, users, action, amount):
    channel = channel.lstrip("#")
    print channel, users, action, amount
    if action == "remove":
        amount = amount * -1
    with db.atomic():
        # creates a given channel entry if not exists
        Channel.get_or_create(channel=channel)
        for user in users:
            # creates a user entry if not exists
            User.get_or_create(username=user.lower())
            try:
                # attempts to retrieve a user object
                ChannelUser.get(username=User.get(username=user.lower()).id,
                                channel=Channel.get(channel=channel).id)
            except ChannelUser.DoesNotExist:
                # if not exists, create channeluser object
                ChannelUser.create(username=User.get(username=user.lower()).id,
                                   channel=Channel.get(channel=channel).id)
            # update the channeluser object to an incremented amount
            print ChannelUser.update(points=ChannelUser.points + amount).where(
                ChannelUser.username == User.get(username=user.lower()).id,
                ChannelUser.channel == Channel.get(
                    channel=channel).id).execute()
    return
コード例 #3
0
ファイル: points.py プロジェクト: singlerider/docbot
def modify_points(channel, users, action, amount):
    channel = channel.lstrip("#")
    print channel, users, action, amount
    if action == "remove":
        amount = amount * -1
    with db.atomic():
        # creates a given channel entry if not exists
        Channel.get_or_create(channel=channel)
        for user in users:
            # creates a user entry if not exists
            User.get_or_create(username=user.lower())
            try:
                # attempts to retrieve a user object
                ChannelUser.get(
                    username=User.get(username=user.lower()).id,
                    channel=Channel.get(channel=channel).id)
            except ChannelUser.DoesNotExist:
                # if not exists, create channeluser object
                ChannelUser.create(username=User.get(
                    username=user.lower()).id, channel=Channel.get(
                        channel=channel).id)
            # update the channeluser object to an incremented amount
            print ChannelUser.update(
                points=ChannelUser.points + amount
            ).where(
                ChannelUser.username == User.get(username=user.lower()).id,
                ChannelUser.channel == Channel.get(channel=channel).id
            ).execute()
    return
コード例 #4
0
ファイル: bot.py プロジェクト: singlerider/docbot
 def save_message(self, username, channel, message):
     channel = channel.lstrip("#")
     User.get_or_create(username=username)
     Channel.get_or_create(channel=channel)
     username_id = User.get(username=username).id
     channel_id = Channel.get(channel=channel).id
     Message.create(
         username=username_id, channel=channel_id, message=message)
コード例 #5
0
 def save_message(self, username, channel, message):
     channel = channel.lstrip("#")
     User.get_or_create(username=username)
     Channel.get_or_create(channel=channel)
     username_id = User.get(username=username).id
     channel_id = Channel.get(channel=channel).id
     Message.create(username=username_id,
                    channel=channel_id,
                    message=message)
コード例 #6
0
ファイル: bot.py プロジェクト: singlerider/docbot
 def handle_command(self, command, channel, username, message):
     User.get_or_create(username=username)
     moderator = get_moderator(channel, username)
     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) and not moderator:
         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) and not moderator:
         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)
     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
     if commands.check_has_user_level(username, command):
         if not moderator and username != SUPERUSER:
             if commands.commands[command].get("optional") is not None and len(
                     message.split(" ")) < 2:
                 pass
             else:
                 resp = '(%s) : %s' % (
                     username, "This is a moderator-only command!")
                 pbot(resp, channel)
                 self.IRC.send_whisper(username, resp)
                 return
     approved_channels = [
         PRIMARY_CHANNEL, BOT_USER, SUPERUSER, TEST_USER, EXTRA_CHANNEL]
     if channel.lstrip("#") not in approved_channels:
         prevented_list = []
         if command.lstrip("!") in prevented_list:
             return
     result = commands.pass_to_function(
         command, args, username=username, channel=channel.lstrip("#"),
         irc=self.IRC)
     commands.update_last_used(command, channel)
     if result:
         resp = '(%s) : %s' % (username, result)
         pbot(resp, channel)
         # self.save_message(BOT_USER, channel, resp)  # pragma: no cover
         return resp[:350]
コード例 #7
0
ファイル: addquote.py プロジェクト: singlerider/docbot
def addquote(args, **kwargs):
    username = kwargs.get("username", "testuser")
    channel = kwargs.get("channel", "testchannel")
    User.get_or_create(username=username.lower())
    Channel.get_or_create(channel=channel)
    quote = unicode(args[0].strip().strip("\"").strip("\'"), 'utf-8')
    if len(quote) > 200:
        return "Let's keep it below 200 characters?"
    game = "offline"
    stream = Twitch(channel, username).stream()["stream"]
    print stream
    if stream is not None:
        game = stream["game"]
    username_id = User.get(User.username == username).id
    channel_id = Channel.get(Channel.channel == channel).id
    Quote.create(username=username_id, channel=channel_id, message=quote, game=game)
    return "{0} added!".format(quote)
コード例 #8
0
ファイル: moderators.py プロジェクト: singlerider/docbot
def add_moderator(channel, user):
    channel = channel.lstrip("#")
    ChannelUser.update(
        is_moderator=1
    ).where(
        ChannelUser.username == User.get(username=user).id,
        ChannelUser.channel == Channel.get(channel=channel).id,
        ChannelUser.is_moderator == 0
    ).execute()
コード例 #9
0
ファイル: addquote.py プロジェクト: singlerider/docbot
def addquote(args, **kwargs):
    username = kwargs.get("username", "testuser")
    channel = kwargs.get("channel", "testchannel")
    User.get_or_create(username=username.lower())
    Channel.get_or_create(channel=channel)
    quote = unicode(args[0].strip().strip("\"").strip("\'"), 'utf-8')
    if len(quote) > 200:
        return "Let's keep it below 200 characters?"
    game = "offline"
    stream = Twitch(channel, username).stream()["stream"]
    print stream
    if stream is not None:
        game = stream["game"]
    username_id = User.get(User.username == username).id
    channel_id = Channel.get(Channel.channel == channel).id
    Quote.create(username=username_id,
                 channel=channel_id,
                 message=quote,
                 game=game)
    return "{0} added!".format(quote)
コード例 #10
0
ファイル: moderators.py プロジェクト: singlerider/docbot
def get_moderator(channel, user):
    channel = channel.lstrip("#")
    try:
        # attempts to retrieve a user object
        is_mod = ChannelUser.get(
            username=User.get(username=user).id,
            channel=Channel.get(channel=channel).id).is_moderator
        return is_mod
    except ChannelUser.DoesNotExist:
        # if not exists, create channeluser object
        is_mod = None
        return is_mod
コード例 #11
0
ファイル: ammo.py プロジェクト: singlerider/docbot
def cron(channel=None):
    import globals
    from src.models.model import User, Channel, ChannelUser, db
    from src.lib.twitch import Twitch
    from src.lib.moderators import add_moderator
    channel = channel.lstrip("#")
    try:
        if Twitch(channel, None).stream().get("stream") is None:
            globals.CHANNEL_INFO[channel.lstrip("#")]["online"] = False
            return
        globals.CHANNEL_INFO[channel.lstrip("#")]["online"] = True
        user_dict, all_users = Twitch(channel, None).users()
        with db.atomic():
            # creates a given channel entry if not exists
            Channel.get_or_create(channel=channel)
            for user in all_users:
                # creates a user entry if not exists
                User.get_or_create(username=user.lower())
                try:
                    # attempts to retrieve a user object
                    ChannelUser.get(
                        username=User.get(username=user.lower()).id,
                        channel=Channel.get(channel=channel).id)
                except ChannelUser.DoesNotExist:
                    # if not exists, create channeluser object
                    ChannelUser.create(username=User.get(
                        username=user.lower()).id, channel=Channel.get(channel=channel).id)
                # update the channeluser object to an incremented amount
                ChannelUser.update(
                    points=ChannelUser.points + 1,
                    time_in_chat=ChannelUser.time_in_chat + 5
                ).where(
                    ChannelUser.username == User.get(username=user.lower()).id,
                    ChannelUser.channel == Channel.get(channel=channel).id
                ).execute()
        for user in user_dict["chatters"]["moderators"]:
            add_moderator(channel, user)
        return
    except:
        pass
コード例 #12
0
def leaderboard(**kwargs):
    channel = kwargs.get("channel")
    top_ten = ChannelUser.raw(
        """
        SELECT * FROM channelusers WHERE channel_id = ? ORDER BY points DESC LIMIT 10
    """,
        Channel.get(channel=channel).id)
    print[x for x in top_ten]
    resp = " | ".join([
        str(x[0] + 1) + ") " + User.get(id=x[1].username_id).username + " " +
        str(x[1].points) for x in enumerate(top_ten)
    ])
    return resp
コード例 #13
0
ファイル: custom_commands.py プロジェクト: singlerider/docbot
def add(
        channel, username, trigger, response, user_level, time_interval,
        times_used):
    channel = channel.lstrip("#")
    if commands.get(trigger) is not None:
        return "{0} is already a builtin command in {1}!".format(
            trigger, channel)
    with db.atomic():
        User.get_or_create(username=username)
        Channel.get_or_create(channel=channel)
        try:
            # attempts to retrieve a user object
            Command.get(
                channel=Channel.get(channel=channel).id,
                trigger=trigger)
            return "{0} already exists in {1}!".format(trigger, channel)
        except Command.DoesNotExist:
            # if not exists, create channeluser object
            Command.create(
                username=User.get(username=username).id,
                channel=Channel.get(channel=channel).id,
                trigger=trigger, response=response, user_level=user_level,
                time_interval=time_interval, time_used=0)
コード例 #14
0
ファイル: ammo.py プロジェクト: singlerider/docbot
def ammo(args, **kwargs):
    username = kwargs.get("username")
    channel = kwargs.get("channel")
    if len(args) < 1:
        try:
            point_value = ChannelUser.get(
                username=User.get(username=username.lower()).id,
                channel=Channel.get(channel=channel).id).points
            time_value = ChannelUser.get(
                username=User.get(username=username.lower()).id,
                channel=Channel.get(channel=channel).id).time_in_chat
        except ChannelUser.DoesNotExist:
            point_value = 0
            time_value = 0
        except Exception as error:
            return error
        resp = "You have {0} ammo and have been watching for {1} minutes".format(
            point_value, time_value)
        return resp
    if len(args) == 1:
        user_to_check = args[0].lower()
        User.get_or_create(username=user_to_check)
        try:
            point_value = ChannelUser.get(
                username=User.get(username=user_to_check).id,
                channel=Channel.get(channel=channel).id).points
            time_value = ChannelUser.get(
                username=User.get(username=user_to_check).id,
                channel=Channel.get(channel=channel).id).time_in_chat
        except ChannelUser.DoesNotExist:
            resp = "{0} not found".format(user_to_check)
            return resp
        except Exception as error:
            return error
        resp = "{0} has {1} ammo and has been watching for {2} minutes".format(
            user_to_check, point_value, time_value)
        return resp
    if len(args) == 3:
        action = args[0]
        username_to_modify = args[1].lower()
        amount = args[2]
        try:
            amount = int(amount)
        except:
            return "Amount must be a number."
        if action == "add" or action == "remove":
            modify_points(channel, [username_to_modify], action, amount)
            return (
                str(amount) + " ammo " + action.rstrip("e") + "ed on " +
                username_to_modify + "!")
        else:
            return "Action must be \"add\" or \"remove\"."
    else:
        return "\"!ammo\" takes either 0, 1, or 3 arguments."
コード例 #15
0
 def handle_command(self, command, channel, username, message):
     User.get_or_create(username=username)
     moderator = get_moderator(channel, username)
     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) and not moderator:
         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) and not moderator:
         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)
     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
     if commands.check_has_user_level(username, command):
         if not moderator and username != SUPERUSER:
             if commands.commands[command].get(
                     "optional") is not None and len(
                         message.split(" ")) < 2:
                 pass
             else:
                 resp = '(%s) : %s' % (username,
                                       "This is a moderator-only command!")
                 pbot(resp, channel)
                 self.IRC.send_whisper(username, resp)
                 return
     approved_channels = [
         PRIMARY_CHANNEL, BOT_USER, SUPERUSER, TEST_USER, EXTRA_CHANNEL
     ]
     if channel.lstrip("#") not in approved_channels:
         prevented_list = []
         if command.lstrip("!") in prevented_list:
             return
     result = commands.pass_to_function(command,
                                        args,
                                        username=username,
                                        channel=channel.lstrip("#"),
                                        irc=self.IRC)
     commands.update_last_used(command, channel)
     if result:
         resp = '(%s) : %s' % (username, result)
         pbot(resp, channel)
         # self.save_message(BOT_USER, channel, resp)  # pragma: no cover
         return resp[:350]