Example #1
0
async def mybirthday(ctx, *, arg):  # command for giving the bot you birthday
    message = ctx.message

    date = parsedate((arg))
    age = calcAge(datetime.date(date[-1], date[-3], date[-2]))
    if os.path.exists(filename):
        print('adding birthday data....')
        with open(filename, 'r') as jsonFile:
            l = (json.load(jsonFile))
        if str(message.guild.id) in l:
            l[str(message.guild.id)].append({str(message.author): {arg: age}})
        else:
            l[str(message.guild.id)] = [{str(message.author): {arg: age}}]
        with open(filename, 'w') as f:
            json.dump(l, f, sort_keys=True, indent=4)
        await ctx.send(
            f'{message.author.display_name} birthday is now in the Database')
        print('stored in Json....')
    else:
        datastore[str(message.guild.id)] = [({
            str(message.author): {
                arg: age
            }
        })]
        print("added data in dic.....")
        with open(filename, 'w') as f:
            json.dump(datastore, f, indent=4)
        await ctx.send(
            f'``{message.author.display_name}`` birthday is now ``in`` the Database'
        )
        print('exiting ready....')
Example #2
0
async def author(ctx, *arg):
    birth = 'March 2, 1998'
    date = parsedate((birth))
    age = calcAge(datetime.date(date[-1], date[-3], date[-2]))
    for i in arg:
        if i == 'age':
            await ctx.send(f'Snow is ``{age}`` years old')
        elif i == 'born' or i == 'birthday' or i == 'birth':
            await ctx.send(f'Snow\'s birthday is on ``{birth}`` ')
        else:
            await ctx.send(
                'give the comman these arguments: ``age``,  ``born``, ``birth``'
            )
Example #3
0
async def bdayReminder():
    if os.path.exists(filename):
        with open(filename, 'r') as jsonFile:
            loading = (json.load(jsonFile))
        for server in loading:
            for obj in loading[server]:
                for user in obj:
                    # print(user)
                    for birth in obj[user]:
                        print(birth)
                        if birthAlert(str(birth)):
                            print('in this ')
                            id = int(server)
                            channels = bot.get_guild(id).text_channels
                            age = 0
                            com = 0
                            max = ''
                            print(len(loading[server]))
                            # print(f'this is array{loading[server][0][user][birth]}')
                            for i in range(len(loading[server])):
                                if user in loading[server][i]:
                                    print('were in')
                                    date = parsedate((birth))
                                    age = calcAge(
                                        datetime.date(date[-1], date[-3],
                                                      date[-2]))
                                    loading[server][i][user][birth] = age
                            with open(filename, 'w') as f:
                                json.dump(loading, f, indent=4)
                            for channel in channels:
                                messages = await channel.history(limit=None
                                                                 ).flatten()
                                if com < len(messages):
                                    max = channel.name
                                    com = len(messages)
                                    print(com)
                            for channel in channels:
                                print('passed')
                                if channel.name.lower() == max:
                                    await channel.send(
                                        f'@here Happy ``{age}`` birthday to ``{user}``! '
                                    )