コード例 #1
0
 async def stop_notify(self, ctx, *, character):
     """Removes the user to the list of people to notified when <character> is posted with the 'its' command.
     Only removes the user from that character's notices."""
     sender = ctx.author.mention
     notice_key = str(ctx.guild.id) + "\\" + str(
         self.resolve_server_alias(ctx, character.title()))
     current_notices = [None]
     try:
         current_notices = self.notify_user_list[notice_key]
         log("def stop_notify: {0}".format(current_notices), 'vf',
             self.args)
         current_notices.remove(sender)
         self.notify_user_list[notice_key] = current_notices
     except KeyError:
         await ctx.send(
             "I don't show that anyone signed up for notices regarding {0}, {1}"
             .format(character, sender))
         return
     except ValueError:
         await ctx.send(
             "I don't show that you're signed up for notices regarding {0}, {1}"
             .format(character, sender))
         return
     await ctx.send(
         "Thanks, {0}, you've successfully been removed from the notice list for {1}"
         .format(sender, character))
コード例 #2
0
    async def wotd(self, ctx):
        """Prints the Waifu of the Day"""
        log("def wotd: wotd invoked by " + str(ctx.author.mention), 'vf',
            self.args)
        # TODO: implement admin/channel permissions for listing waifu on rotating schedule

        await ctx.send("Astolfo, always")
コード例 #3
0
 def itis(self, ctx, character):
     """Takes a Discord Context ctx and string character as arguments and sends notices to all users signed up for them"""
     log("def itis: character: " + character, 'vf', self.args)
     notify_users = None
     resolved_character = str(
         self.resolve_server_alias(ctx, character.title()))
     log("def itis: resolved character: " + resolved_character, 'vf',
         self.args)
     # we're only going to look for notices registered for the server where the command got called
     user_key = str(ctx.guild.id) + "\\" + resolved_character
     log("def itis: user_key: " + user_key, 'vf', self.args)
     try:
         notify_users = self.notify_user_list[user_key]
         log("def itis: notify_users: " + str(notify_users), 'vf',
             self.args)
         if not notify_users:  # if no values get returned for a <character>
             raise KeyError
     except KeyError:
         return str("Oops! I don't have an alert for {0}, {1}\n".format(
             resolved_character, ctx.author.mention))
     to_notify = 'Hey,'
     for user in notify_users:
         to_notify = to_notify + ' ' + user
     to_notify = to_notify + ', it\'s ' + resolved_character
     to_notify += "\n"
     return to_notify
コード例 #4
0
 async def stop_all_notices(self, ctx):
     """Stops all notices on this server for the user. Causes the command to enter a 30 second cooldown
     and the bot shows it is typing while running as it is a potentially slow operation"""
     async with ctx.typing():
         sender = ctx.author.mention
         notify_keys = list(self.notify_user_list.keys())
         halt_keys = []
         log(
             "def stop_all_notices: stop_all_notices invoked by {0}".format(
                 sender), 'vf', self.args)
         for key in notify_keys:
             log("def stop_all_notices: " + str(key), 'vf', self.args)
             if sender in self.notify_user_list[key]:
                 log(
                     "def stop_all_notices: " +
                     str(self.notify_user_list[key]), 'vf', self.args)
                 current_notices = self.notify_user_list[key]
                 log("def stop_all_notices: {0}".format(current_notices),
                     'vf', self.args)
                 current_notices.remove(sender)
                 self.notify_user_list[key] = current_notices
                 halt_keys.append(key)
         end_msg = "Notices ended for the following characters: \n"
         for key in halt_keys:
             key_ns = str(key).partition('\\')[2]
             end_msg += key_ns + " "
         await ctx.send(end_msg)
コード例 #5
0
ファイル: wfbot.py プロジェクト: JordanKinsley/WaifuHoarder
async def on_ready():
    try:
        if args.log_file:
            with(open(args.log_file, 'a')) as lf:
                lf.truncate()
    except OSError:
        print("log file at {0} not found".format(args.log_file))
    log('Logged in as', 'sf', args)
    log(bot.user.name, 'sf', args)
    log(bot.user.id, 'sf', args)
    log('~~--~~--~~--~~', 'sf', args)
コード例 #6
0
 async def add_alias(self, ctx, alias, character):
     """Assign an alias to a character, see notes.
     alias "<alias>" "<character>" - The "alias" is the new way to refer to "character".
     "Character" is the original notice assignment. Using quotes (") is key, otherwise the bot will not parse the characters correctly"""
     log("def add_alias: alias: " + alias, 'vf', self.args)
     log("def add_alias: character: " + character, 'vf', self.args)
     current_server = str(ctx.guild.id)
     sender = ctx.author.mention
     new_alias = current_server + '\\' + alias.title()
     try:
         existing_alias = self.character_aliases[new_alias]
         if existing_alias:
             await ctx.send(
                 "{0} is already referenced by alias {1}, {2}".format(
                     existing_alias, new_alias, sender))
         else:
             raise KeyError
     except KeyError:
         self.character_aliases[new_alias] = character
         await ctx.send(
             "OK, notices for {0} will triggered if someone uses `its {1}` from now on."
             .format(character, alias))
コード例 #7
0
 async def known_aliases(self, ctx):
     """Returns a list of all known aliases for this server. Has a cooldown of 60 seconds as this is a potentially time consuming request"""
     current_server = str(ctx.guild.id)
     start = datetime.datetime.now()
     async with ctx.typing():
         aliases = list(self.character_aliases.keys())
         aliases = sorted(aliases)
         end = datetime.datetime.now()
         alias_list = "I know of the following aliases: \n"
         for alias in aliases:
             alias_t = alias.partition(
                 '\\')  # returns a tuple of <server id>, \, and <alias>
             if alias_t[0] != current_server:
                 pass
             else:
                 alias_list += alias_t[2] + " (refers to "
                 alias_list += str(self.character_aliases[alias]) + ")\n"
         log("def known_aliases: time elapsed: {0}".format(end - start),
             'vf', self.args)
         results = discord_split(alias_list)
         for result in results:
             await ctx.send(result, delete_after=300)
コード例 #8
0
 async def known_waifus(self, ctx):
     """Lists the waifus known by the bot for this server. Has a cooldown of 60 seconds as this is a potentially time consuming request"""
     start = datetime.datetime.now()
     # running the .keys() function on shelf object is time consuming. We're going to measure the time it took
     async with ctx.typing():
         waifus = list(self.notify_user_list.keys())
         waifus = sorted(waifus)
         end = datetime.datetime.now()
         waifu_list = 'I know of the following waifus: '
         for waifu in waifus:
             # split the returned value into (<server>, \, <character>)
             waifu_t = waifu.partition("\\")
             if waifu_t[0] != str(ctx.guild.id):
                 # if the server doesn't match the current server for this command, skip it
                 pass
             else:
                 waifu_list += waifu_t[2] + ', '
         log("def known_waifus: time elapsed: {0}".format(end - start),
             'vf', self.args)
         results = discord_split(waifu_list)
         for result in results:
             await ctx.send(result, delete_after=300)
コード例 #9
0
 async def debug_user_list(self, ctx):
     """An owner-only debug command that lists all users and notices. Suppresses @ mentions"""
     async with ctx.typing():
         notify_keys = list(self.notify_user_list.keys())
         log("def debug_user_list: " + str(notify_keys), 'vf', self.args)
         user_list = ''
         for key in notify_keys:
             log("def debug_user_list: ".format(key), 'vf', self.args)
             user_list += 'key: ' + key + ' user: '******'\n'
         log("def debug_user_list: ".format(user_list), 'vf', self.args)
         user_list = suppress_mentions(user_list)
         await ctx.send(user_list)
コード例 #10
0
 async def do_you_know(self, ctx, *, character):
     """Confirms if the bot knows of a particular <character>."""
     sender = ctx.author.mention
     resolved_character = str(
         self.resolve_server_alias(ctx, character.title()))
     # keys are entered into DB as <server>\<character> and Python strings use \ as an escape character, so a
     # literal "\" requires "\\". Other delimiters were tried, but failed
     notice_key = str(ctx.guild.id) + "\\" + resolved_character
     try:
         if notice_key in self.notify_user_list:
             log(
                 "def do_you_know: notice key found: {0}".format(
                     notice_key), 'vf', self.args)
             if sender in self.notify_user_list[notice_key]:
                 log("def do_you_know: sender on notice list", 'vf',
                     self.args)
                 await ctx.send(
                     "Yes, I know of {0} and you're all set to hear when they get posted next!"
                     .format(resolved_character))
             else:
                 log("def do_you_know: sender not on notice list", 'vf',
                     self.args)
                 await ctx.send(
                     "Yes, I know of {0}! I don't see you signed up for notices for them. Sign up with `{1}notifyme {0}`"
                     .format(resolved_character, ctx.bot.command_prefix))
         else:
             await ctx.send(
                 "No, I don't have anything on {0}! Sign up with `{1}notifyme {0}`"
                 .format(resolved_character, ctx.bot.command_prefix))
     except KeyError:
         log(
             "def do_you_know: notice key not found: {0}".format(
                 notice_key), 'vf', self.args)
         await ctx.send(
             "No, I don't have anything on {0}! Sign up with `{1}notifyme {0}`"
             .format(resolved_character, ctx.bot.command_prefix))
コード例 #11
0
 async def my_notices(self, ctx):
     """Lists all notices on this server for the user. Causes the command to enter a 30 second cooldown
     and the bot shows it is typing while running as it is a potentially slow operation"""
     async with ctx.typing():
         sender = ctx.author.mention
         notify_keys = list(self.notify_user_list.keys())
         all_keys = []
         log("def my_notices: my_notices invoked by {0}".format(sender),
             'vf', self.args)
         for key in notify_keys:
             log("def my_notices: " + str(key), 'vf', self.args)
             if sender in self.notify_user_list[key]:
                 log("def my_notices: " + str(self.notify_user_list[key]),
                     'vf', self.args)
                 all_keys.append(key)
         end_msg = "You are signed up for notices for the following characters: \n"
         all_keys = sorted(all_keys)
         for key in all_keys:
             key_ns = str(key).partition('\\')[2]
             end_msg += key_ns + ", "
         await ctx.send(end_msg)
コード例 #12
0
ファイル: wfbot.py プロジェクト: JordanKinsley/WaifuHoarder
parser.add_argument("-f", "--file", help="load token from file")
parser.add_argument("-t", "--token", help="specify token in arguments")
parser.add_argument("-p", "--prefix", help="command prefix")
# if -v is passed on command line, no need to add argument following
parser.add_argument("-v", "--verbose", help="verbose mode (prints more info to terminal)", action="store_true")
parser.add_argument("-c", "--character", help="file location for character alias shelf")
parser.add_argument("-u", "--userlist", help="file location for user list shelf")
parser.add_argument("-lf", "--log_file", help="file location for logging")
args = parser.parse_args()

if args.file:
    file_token = read_token(args.file)  # try reading the supplied file token in, but if it fails, use default
    if file_token is None:
        if default_token:
            discord_api_token = default_token
            log("default token used: {0}".format(default_token), 'svf', args)
        else:
            print("no valid token supplied, exiting")
            quit(1)
    else:
        discord_api_token = file_token
        log("Loaded token from file: {0}".format(file_token), 'svf', args)
elif args.token:
    discord_api_token = args.token
    log("using token from cli: {0}".format(args.token), 'svf', args)

prefix = ''
if args.prefix:
    prefix = args.prefix
else:
    prefix = ';'
コード例 #13
0
 def notify(self, ctx, character):
     sender = ctx.author.mention
     log("def notify: {0}".format(sender), 'vf', self.args)
     log("def notify: guild: " + str(ctx.guild), 'vf', self.args)
     log("def notify: guild id: " + str(ctx.guild.id), 'vf', self.args)
     resolved_character = str(
         self.resolve_server_alias(ctx, character.title()))
     notice_key = str(ctx.guild.id) + "\\" + resolved_character
     log("def notify: " + notice_key, 'vf', self.args)
     current_notices = [None]
     try:
         current_notices = self.notify_user_list[notice_key]
         log(
             "def notify: key found, current notices: " +
             str(current_notices), 'vf', self.args)
         if sender in current_notices:
             return str(
                 "You've already signed up for notices for {0}, {1}\n".
                 format(resolved_character, sender))
         current_notices.append(sender)
     except KeyError:
         current_notices[0] = sender
         log(
             "def notify: key not found, current notices: " +
             str(current_notices), 'vf', self.args)
     self.notify_user_list[notice_key] = current_notices
     return str(
         'Thanks {0}, you\'ve successfully been added to the notice list for {1}\n'
         .format(sender, resolved_character))
コード例 #14
0
 def resolve_server_alias(self, ctx, character):
     """Internal command to help resolve an input <character> with any existing aliases.
     If <character> matches an existing alias, returns the character the alias refers to.
     If <character> does not match an alias, returns <character>"""
     current_server = str(ctx.guild.id)
     check_alias = current_server + '\\' + character
     log("def resolve_server_alias: check_alias: " + check_alias, 'vf',
         self.args)
     resolved_character = ''
     try:
         # if we find that <character> refers to an alias in our character aliases, return the character referred to
         # by that alias. If this fails, it throws a KeyError, caught below
         full_character = self.character_aliases[check_alias]
         log(
             "def resolve_server_alias: full_character: {0}".format(
                 full_character), 'vf', self.args)
         resolved_character = full_character.replace(current_server, '')
         log(
             "def resolve_server_alias: resolved_character: " +
             resolved_character, 'vf', self.args)
     except KeyError:
         # if we don't find any aliases, just return the character
         resolved_character = character
     log("def resolve_server_alias: post character: " + character, 'vf',
         self.args)
     log(
         "def resolve_server_alias: post resolved_character: " +
         resolved_character, 'vf', self.args)
     log("def resolve_server_alias: post check_alias: " + check_alias, 'vf',
         self.args)
     return resolved_character