Advertisement
Huskymeister

Methuselah Bot Bak 31/08/17

Aug 31st, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.07 KB | None | 0 0
  1. import discord
  2. import asyncio
  3. import random
  4. import time
  5.  
  6. client = discord.Client()
  7. d10 = [1,2,3,4,5,6,7,8,9,10]
  8.  
  9. '''
  10. If making a suggestion or giving a code implementation for a feature,
  11. please ensure it is commented and has a help message for using the
  12. command.
  13. '''
  14.  
  15. ''' TODO List '''
  16.  
  17.  
  18. ''' SERVER OWNERS - EDIT HERE ONLY '''
  19. server_id = '352595662837252098'
  20. untrusted_member_id = '352596761652625420'
  21. welcome_channel_id = '352595662837252099'
  22. token = 'MzUyNTk5NDIzMzgyOTc4NTcw.DIjikA.2FiOo0QD70Y8NxC6KVtuCI7ig-Y'
  23. ''' STOP EDITTING HERE '''
  24.  
  25. @client.event
  26. async def on_ready():
  27.     print('Logged in as')
  28.     print(client.user.name)
  29.     print(client.user.id)
  30.     print('------')
  31.     print('Connected Servers')
  32.     for s in client.servers:
  33.         print(s.name)
  34.  
  35. @client.event
  36. async def on_message(message):
  37.     #Display the roles of the user who asked
  38.     if message.content.startswith('!role'):
  39.         for r in message.author.roles:
  40.             await client.send_message(message.channel, r.id + " - " + r.name)
  41.    
  42.     #Display all the roles for their server with the IDs attached
  43.     elif message.content.startswith('!allroles'):
  44.         for r in message.server.roles:
  45.             await client.send_message(message.channel, r.id + " - " + r.name)
  46.            
  47.     # Roll a D10 using Vampire the Masquerade's rules.
  48.     elif message.content.startswith('!roll') or message.content.startswith('!r'):
  49.         tmp = ''
  50.         if message.content.startswith('!roll'):
  51.             tmp = message.content[5:]
  52.         else:
  53.             tmp = message.content[2:]
  54.         args = tmp.split(' ')
  55.  
  56.         #Display help message for the rolling command.
  57.         if args[0] == '-h' or args[0] == '-help' or len(args) == 1:
  58.             await client.send_message(message.channel, "This command allows you to roll a number of 10-Sided dice following the dice rules for Vampire the Masquerade, add T or TRUE to the end of the command to add the specialisation rule.\nFormat is \n```!roll Stat1 Stat2 Difficulty``` \nOR \n```!roll Total_Dice Difficulty```")
  59.             return;
  60.        
  61.         #Check if argument length is within boundary.
  62.         elif len(args) > 1 and len(args) < 5:
  63.             del args[0]
  64.             #Check arguments to ensure they are all numbers
  65.             for a in range(1, len(args)-1):
  66.                 if not args[a].isdigit():
  67.                     await client.send_message(message.channel, "You can't roll using letters silly!")
  68.                     return;
  69.            
  70.             #Start of rolling. arg format;
  71.             #Stat1, Stat2, Difficulty, Specialised  OR  Total_Dice, Difficulty, Specialised
  72.            
  73.             #Assume second format unless there's more arguments.
  74.             number_of_dice = int(args[0])
  75.             difficulty = int(args[1])
  76.            
  77.             #Check if player has a specialisation for crit role (3 arguments).
  78.             spec = False
  79.             if len(args) == 3 and not args[2].isdigit():
  80.                 if args[2].upper() == "TRUE" or args[2].upper() == "T":
  81.                     spec = True
  82.            
  83.             #Adds two stats together for total dice. Then checks specialisation.
  84.             if(len(args) >= 3 and args[2].isdigit()):
  85.                 number_of_dice = number_of_dice + int(args[1])
  86.                 difficulty = int(args[2])
  87.                 if len(args) == 4 and not args[3].isdigit():
  88.                     if args[3].upper() == "TRUE" or args[3].upper() == "T":
  89.                         spec = True
  90.            
  91.            
  92.             #Ensure that difficulty is not impossible.
  93.             if difficulty > 10:
  94.                 await client.send_message(message.channel, "Woah! That task is impossible. Take it easy on your players eh?")
  95.             else:
  96.                 #Create a list with a size of the number of dice then
  97.                 #populate with random ints before counting successes.
  98.                 dice_rolls = [None]*number_of_dice
  99.                 successes = 0
  100.                 for i in range(0, number_of_dice):
  101.                     ms = int(round(time.time() * 1000))
  102.                     str_ms = str(ms)
  103.                     rand = random.sample(str_ms,1)
  104.                     dice_rolls[i] = int(rand[0]) + 1
  105.                
  106.                 #Counting successes. Using botch and specialisation rules.
  107.                 botched = False
  108.                 cantBotch = False
  109.                 for r in dice_rolls:
  110.                     if r >= difficulty and not r == 10:
  111.                         successes = successes + 1
  112.                         cantBotch = True
  113.                         botched = False
  114.                     elif r == 1:
  115.                         successes = successes - 1
  116.                         if not cantBotch:
  117.                             botched = True
  118.                     elif r == 10 and spec == True:
  119.                         successes = successes + 2
  120.                         cantBotch = True
  121.                         botched = False
  122.                    
  123.            
  124.                 #Show result of how many successes
  125.                 if not botched:
  126.                     await client.send_message(message.channel, "You rolled " + str(number_of_dice) + "d10s, difficulty " + str(difficulty) + " and you got.\n" + str(dice_rolls) + "\n***" + str(successes) + " Success(es)***")
  127.                 else:
  128.                     await client.send_message(message.channel, "You rolled " + str(number_of_dice) + "d10s, difficulty " + str(difficulty) + " and you got.\n" + str(dice_rolls) + "\n***YOU BOTCHED! WITH " + str(successes) + " SUCCESS(ES)***")
  129.         else:
  130.             #Show error message if there is too many/little arguments.
  131.             await client.send_message(message.channel, "Wrong number of arguments. Consult !roll -h for help")
  132.  
  133. @client.event
  134. async def on_member_join(member):
  135.     await client.send_message(client.get_channel(welcome_channel_id), "@here please welcome the newly sired Cainite " + member.mention)
  136.     server = client.get_server(server_id)
  137.     for r in server.roles:
  138.         if r.id == untrusted_member_id:
  139.             await client.add_roles(member, r)
  140.  
  141. client.run(token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement