示例#1
0
async def restrict(message, client):
  if not message.author.guild_permissions.administrator:
    await message.channel.send(embed=discord.Embed(description='You must be an admin to run this command'))
    return

  if message.channel.id not in restrictions.keys():
    restrictions[message.channel.id] = []

  disengage_all = True
  args = 0

  for role in message.role_mentions:
    args = 1
    if role.id not in restrictions[message.channel.id]:
      disengage_all = False
    restrictions[message.channel.id].append(role.id)

  if disengage_all and args:
    for role in message.role_mentions:
      restrictions[message.channel.id].remove(role.id)
      restrictions[message.channel.id].remove(role.id)

    await message.channel.send(embed=discord.Embed(description='Disabled channel reminder permissions for roles.'))

  elif args:
    await message.channel.send(embed=discord.Embed(description='Enabled channel reminder permissions for roles.'))

  else:
    await message.channel.send(embed=discord.Embed(description='Allowed: {}'.format(' '.join(['<@&' + str(i) + '>' for i in restrictions[message.channel.id]]))))

  with open('DATA/restrictions.json', 'w') as f:
    json.dump(restrictions, f)
示例#2
0
async def set_interval(message, client):

    if message.author not in get_patrons('Donor'):
        await message.channel.send(embed=discord.Embed(
            description=
            'You need to be a Patron (donating 2$ or more) to access this command! Type `$donate` to find out more.'
        ))
        return

    args = message.content.split(' ')
    args.pop(0)  # remove the command item

    if len(args) < 3:
        await message.channel.send(embed=discord.Embed(
            title='interval',
            description=
            '**Usage** ```$interval [channel mention or user mention] <time to or time at> <interval> <message>```\n\n**Example** ```$interval #general 9:30 1d Good morning!``` ```$interval 0s 10s This will be really irritating```'
        ))
        return

    scope = message.channel.id
    pref = '#'

    if args[0].startswith('<'):  # if a scope is provided
        if args[0][2:-1][0] == '!':
            tag = int(args[0][3:-1])

        else:
            try:
                tag = int(args[0][2:-1])
            except ValueError:
                await message.channel.send(embed=discord.Embed(
                    description=
                    'Please ensure your tag links directly to a user or channel, not a role.'
                ))

        if args[0][1] == '@':  # if the scope is a user
            pref = '@'
            scope = message.guild.get_member(tag)

        else:
            pref = '#'
            scope = message.guild.get_channel(tag)

        if scope == None:
            await message.channel.send(embed=discord.Embed(
                description='Couldn\'t find a location by your tag present.'))
            return

        else:
            scope = scope.id

        args.pop(0)

    msg_time = format_time(args[0], message.guild.id)

    if msg_time == None:
        await message.channel.send(embed=discord.Embed(
            description=
            'Make sure the time you have provided is in the format of [num][s/m/h/d][num][s/m/h/d] etc. or `day`/`month`/`year`-`hour`:`minute`:`second`.\n\n*This feature was reworked on the 21/01/2018. Please check the help menu*'
        ))
        return

    args.pop(0)

    msg_interval = format_time(args[0], message.guild.id)

    if msg_interval == None:
        await message.channel.send(embed=discord.Embed(
            description=
            'Make sure the interval you have provided is in the format of [num][s/m/h/d][num][s/m/h/d] etc. with no spaces, eg. 10s for 10 seconds or 10s12m15h1d for 10 seconds, 12 minutes, 15 hours and 1 day.'
        ))
        return
    elif msg_interval < 8:
        await message.channel.send(embed=discord.Embed(
            description=
            'Please make sure your interval timer is longer than 8 seconds.'))
        return

    msg_interval -= time.time()
    msg_interval = round(msg_interval)

    args.pop(0)

    msg_text = ' '.join(args)

    if len(msg_text) > 150 and message.author not in get_patrons('Patrons'):
        await message.channel.send(embed=discord.Embed(
            description=
            'Interval message too long! (max 150, you used {}). Use `$donate` to increase your character limit to 400 ($5 tier)'
            .format(len(msg_text))))
        return

    if pref == '#':
        if not message.author.guild_permissions.administrator:
            if scope not in restrictions.keys():
                restrictions[scope] = []
            for role in message.author.roles:
                if role.id in restrictions[scope]:
                    break
            else:
                await message.channel.send(embed=discord.Embed(
                    description=
                    'You must be either admin or have a role capable of sending reminders to that channel. Please talk to your server admin, and tell her/him to use the `$restrict` command to specify allowed roles.'
                ))
                return

    intervals.append([msg_time, msg_interval, scope, msg_text])

    await message.channel.send(embed=discord.Embed(
        description=
        'New interval registered for <{}{}> in {} seconds . You can\'t edit the reminder now, so you are free to delete the message.'
        .format(pref, scope, round(msg_time - time.time()))))
    print('Registered a new interval for {}'.format(message.guild.name))
示例#3
0
async def set_reminder(message, client):
    args = message.content.split(' ')
    args.pop(0)  # remove the command item

    if len(args) < 2:
        await message.channel.send(embed=discord.Embed(
            title='remind',
            description=
            '**Usage** ```$remind [channel mention or user mention] <time to or time at> <message>```\n\n**Example** ```$remind #general 10s Hello world``` ```$remind 10:30 It\'s now 10:30```'
        ))
        return

    scope = message.channel.id
    pref = '#'

    if args[0].startswith('<'):  # if a scope is provided
        if args[0][2:-1][0] == '!':
            tag = int(args[0][3:-1])

        else:
            try:
                tag = int(args[0][2:-1])
            except ValueError:
                await message.channel.send(embed=discord.Embed(
                    description=
                    'Please ensure your tag links directly to a user or channel, not a role.'
                ))
                return

        if args[0][1] == '@':  # if the scope is a user
            pref = '@'
            scope = message.guild.get_member(tag)

        else:
            pref = '#'
            scope = message.guild.get_channel(tag)

        if scope == None:
            await message.channel.send(embed=discord.Embed(
                description='Couldn\'t find a location by your tag present.'))
            return

        else:
            scope = scope.id

        args.pop(0)

    msg_time = format_time(args[0], message.guild.id)

    if msg_time == None:
        await message.channel.send(embed=discord.Embed(
            description=
            'Make sure the time you have provided is in the format of [num][s/m/h/d][num][s/m/h/d] etc. or `day`/`month`/`year`-`hour`:`minute`:`second`.\n\n*This feature was reworked on the 21/01/2018. Please check the help menu*'
        ))
        return

    args.pop(0)

    msg_text = ' '.join(args)

    if count_reminders(scope) > 5 and message.author not in get_patrons(
            'Patrons'):
        await message.channel.send(embed=discord.Embed(
            description=
            'Too many reminders in specified channel! Use `$del` to delete some of them, or use `$donate` to increase your maximum ($5 tier)'
        ))
        return

    if len(msg_text) > 150 and message.author not in get_patrons('Patrons'):
        await message.channel.send(embed=discord.Embed(
            description=
            'Reminder message too long! (max 150, you used {}). Use `$donate` to increase your character limit to 400 ($5 tier)'
            .format(len(msg_text))))
        return

    if pref == '#':
        if not message.author.guild_permissions.administrator:
            if scope not in restrictions.keys():
                restrictions[scope] = []
            for role in message.author.roles:
                if role.id in restrictions[scope]:
                    break
            else:
                await message.channel.send(embed=discord.Embed(
                    description=
                    'You must be either admin or have a role capable of sending reminders to that channel. Please talk to your server admin, and tell her/him to use the `$restrict` command to specify allowed roles.'
                ))
                return

    calendar.append([msg_time, scope, msg_text])

    await message.channel.send(embed=discord.Embed(
        description=
        'New reminder registered for <{}{}> in {} seconds . You can\'t edit the reminder now, so you are free to delete the message.'
        .format(pref, scope, round(msg_time - time.time()))))
    print('Registered a new reminder for {}'.format(message.guild.name))
示例#4
0
async def del_reminders(message, client):
    if not message.author.guild_permissions.administrator:
        if scope not in restrictions.keys():
            restrictions[scope] = []
        for role in message.author.roles:
            if role.id in restrictions[scope]:
                break
        else:
            await message.channel.send(embed=discord.Embed(
                description=
                'You must be either admin or have a role capable of sending reminders to that channel. Please talk to your server admin, and tell her/him to use the `$restrict` command to specify allowed roles.'
            ))
            return

    await message.channel.send(
        'Listing reminders on this server... (be patient, this might take some time)\nAlso, please note the times are done relative to UK time. Thanks.'
    )

    li = [ch.id for ch in message.guild.channels
          ]  ## get all channels and their ids in the current server

    n = 1
    remli = []

    for inv in intervals:
        if inv[2] in li:
            remli.append(inv)
            await message.channel.send('  **' + str(n) + '**: \'' + inv[3] +
                                       '\' (' +
                                       datetime.fromtimestamp(int(inv[0])).
                                       strftime('%Y-%m-%d %H:%M:%S') + ')')
            n += 1

    for rem in calendar:
        if rem[1] in li:
            remli.append(rem)
            await message.channel.send('  **' + str(n) + '**: \'' + rem[2] +
                                       '\' (' +
                                       datetime.fromtimestamp(int(rem[0])).
                                       strftime('%Y-%m-%d %H:%M:%S') + ')')
            n += 1

    await message.channel.send(
        'List (1,2,3...) the reminders you wish to delete')

    num = await client.wait_for('message',
                                check=lambda m: m.author == message.author and
                                m.channel == message.channel)
    nums = num.content.split(',')

    dels = 0
    for i in nums:
        try:
            i = int(i) - 1
            if i < 0:
                continue
            item = remli[i]
            if item in intervals:
                intervals.remove(remli[i])
                print('Deleted interval')
                dels += 1

            else:
                calendar.remove(remli[i])
                print('Deleted reminder')
                dels += 1

        except ValueError:
            continue
        except IndexError:
            continue

    await message.channel.send('Deleted {} reminders!'.format(dels))
示例#5
0
async def del_reminders(message, client):
    if not isinstance(message.channel, discord.DMChannel):
        if not message.author.guild_permissions.manage_messages:
            scope = message.channel.id
            if scope not in restrictions.keys():
                restrictions[scope] = []
            for role in message.author.roles:
                if role.id in restrictions[scope]:
                    break
            else:
                await message.channel.send(embed=discord.Embed(
                    description=
                    'You must be either admin or have a role capable of sending reminders to that channel. Please talk to your server admin, and tell her/him to use the `$restrict` command to specify allowed roles.'
                ))
                return

        li = [ch.id for ch in message.guild.channels
              ]  ## get all channels and their ids in the current server
    else:
        li = [message.author.id]

    await message.channel.send(
        'Listing reminders on this server... (there may be a small delay, please wait for the "List (1,2,3...)" message)\nAlso, please note the times are done relative to UTC time. Thanks.'
    )

    n = 1
    remli = []

    for rem in reminders:
        if rem.channel in li:
            remli.append(rem)
            await message.channel.send('  **' + str(n) + '**: \'' +
                                       rem.message + '\' (' +
                                       datetime.fromtimestamp(rem.time).
                                       strftime('%Y-%m-%d %H:%M:%S') + ')')
            n += 1

    await message.channel.send(
        'List (1,2,3...) the reminders you wish to delete')

    num = await client.wait_for('message',
                                check=lambda m: m.author == message.author and
                                m.channel == message.channel)
    nums = [n.strip() for n in num.content.split(',')]

    dels = 0
    for i in nums:
        try:
            i = int(i) - 1
            if i < 0:
                continue
            reminders.remove(remli[i])
            print('Deleted reminder')
            dels += 1

        except ValueError:
            continue
        except IndexError:
            continue

    await message.channel.send('Deleted {} reminders!'.format(dels))