Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.60 KB | None | 0 0
  1. @bot.command(pass_context=True)
  2. async def mute(context):
  3.     if len(context.message.content.split()) < 2:
  4.         await send_message(channel=context.message.channel,
  5.                            message='Syntax: a!mute [hours] @Person1... @Person99')
  6.         return
  7.     hours = context.message.content.split()[1]
  8.     hours = float(hours) if hours.replace('.', '').isnumeric() else None
  9.     if hours is not None and not 0 < hours <= 24:
  10.         await send_message(channel=context.message.channel,
  11.                            message='Can only mute between 1 - 24 hours')
  12.         return
  13.     mentions = context.message.mentions
  14.     if not mentions:
  15.         await send_message(channel=context.message.channel,
  16.                            message='You must mention a person for this command.')
  17.         return
  18.     for mention in mentions:
  19.         if hours:
  20.             hours_string = ''
  21.             if hours >= 1:
  22.                 hours_string = ' {hours} hours'.format(hours=int(hours))
  23.             minutes_string = ''
  24.             minutes = (hours - int(hours)) * 60
  25.             if int(minutes):
  26.                 if hours_string:
  27.                     minutes_string += ' and'
  28.                 minutes_string += ' {minutes} minutes'.format(minutes=int(minutes))
  29.             seconds_string = ''
  30.             seconds = (minutes - int(minutes)) * 60
  31.             if seconds:
  32.                 if hours_string:
  33.                     seconds_string += ' and'
  34.                 seconds_string += ' {seconds} seconds'.format(seconds=int(seconds))
  35.             await send_message(channel=context.message.channel,
  36.                                message='Muting {mention} for{hours}{minutes}{seconds}!',
  37.                                mention=mention,
  38.                                hours=hours_string,
  39.                                minutes=minutes_string,
  40.                                seconds=seconds_string),
  41.         else:
  42.             await send_message(channel=context.message.channel,
  43.                                message='Muting {mention} permanently!',
  44.                                mention=mention)
  45.         await bot.server_voice_state(member=mention,
  46.                                      mute=True)
  47.     if hours:
  48.         duration = hours * 3600
  49.         await asyncio.sleep(duration)
  50.         for mention in context.message.mentions:
  51.             await send_message(channel=context.message.channel,
  52.                                message='Time is up, unmuting {mention}.',
  53.                                mention=mention)
  54.             await bot.server_voice_state(member=mention,
  55.                                          mute=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement