Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- import asyncio
- import random
- import time
- client = discord.Client()
- d10 = [1,2,3,4,5,6,7,8,9,10]
- '''
- If making a suggestion or giving a code implementation for a feature,
- please ensure it is commented and has a help message for using the
- command.
- '''
- ''' TODO List '''
- ''' SERVER OWNERS - EDIT HERE ONLY '''
- server_id = '352595662837252098'
- untrusted_member_id = '352596761652625420'
- welcome_channel_id = '352595662837252099'
- token = 'MzUyNTk5NDIzMzgyOTc4NTcw.DIjikA.2FiOo0QD70Y8NxC6KVtuCI7ig-Y'
- ''' STOP EDITTING HERE '''
- @client.event
- async def on_ready():
- print('Logged in as')
- print(client.user.name)
- print(client.user.id)
- print('------')
- print('Connected Servers')
- for s in client.servers:
- print(s.name)
- @client.event
- async def on_message(message):
- #Display the roles of the user who asked
- if message.content.startswith('!role'):
- for r in message.author.roles:
- await client.send_message(message.channel, r.id + " - " + r.name)
- #Display all the roles for their server with the IDs attached
- elif message.content.startswith('!allroles'):
- for r in message.server.roles:
- await client.send_message(message.channel, r.id + " - " + r.name)
- # Roll a D10 using Vampire the Masquerade's rules.
- elif message.content.startswith('!roll') or message.content.startswith('!r'):
- tmp = ''
- if message.content.startswith('!roll'):
- tmp = message.content[5:]
- else:
- tmp = message.content[2:]
- args = tmp.split(' ')
- #Display help message for the rolling command.
- if args[0] == '-h' or args[0] == '-help' or len(args) == 1:
- 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```")
- return;
- #Check if argument length is within boundary.
- elif len(args) > 1 and len(args) < 5:
- del args[0]
- #Check arguments to ensure they are all numbers
- for a in range(1, len(args)-1):
- if not args[a].isdigit():
- await client.send_message(message.channel, "You can't roll using letters silly!")
- return;
- #Start of rolling. arg format;
- #Stat1, Stat2, Difficulty, Specialised OR Total_Dice, Difficulty, Specialised
- #Assume second format unless there's more arguments.
- number_of_dice = int(args[0])
- difficulty = int(args[1])
- #Check if player has a specialisation for crit role (3 arguments).
- spec = False
- if len(args) == 3 and not args[2].isdigit():
- if args[2].upper() == "TRUE" or args[2].upper() == "T":
- spec = True
- #Adds two stats together for total dice. Then checks specialisation.
- if(len(args) >= 3 and args[2].isdigit()):
- number_of_dice = number_of_dice + int(args[1])
- difficulty = int(args[2])
- if len(args) == 4 and not args[3].isdigit():
- if args[3].upper() == "TRUE" or args[3].upper() == "T":
- spec = True
- #Ensure that difficulty is not impossible.
- if difficulty > 10:
- await client.send_message(message.channel, "Woah! That task is impossible. Take it easy on your players eh?")
- else:
- #Create a list with a size of the number of dice then
- #populate with random ints before counting successes.
- dice_rolls = [None]*number_of_dice
- successes = 0
- for i in range(0, number_of_dice):
- ms = int(round(time.time() * 1000))
- str_ms = str(ms)
- rand = random.sample(str_ms,1)
- dice_rolls[i] = int(rand[0]) + 1
- #Counting successes. Using botch and specialisation rules.
- botched = False
- cantBotch = False
- for r in dice_rolls:
- if r >= difficulty and not r == 10:
- successes = successes + 1
- cantBotch = True
- botched = False
- elif r == 1:
- successes = successes - 1
- if not cantBotch:
- botched = True
- elif r == 10 and spec == True:
- successes = successes + 2
- cantBotch = True
- botched = False
- #Show result of how many successes
- if not botched:
- 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)***")
- else:
- 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)***")
- else:
- #Show error message if there is too many/little arguments.
- await client.send_message(message.channel, "Wrong number of arguments. Consult !roll -h for help")
- @client.event
- async def on_member_join(member):
- await client.send_message(client.get_channel(welcome_channel_id), "@here please welcome the newly sired Cainite " + member.mention)
- server = client.get_server(server_id)
- for r in server.roles:
- if r.id == untrusted_member_id:
- await client.add_roles(member, r)
- client.run(token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement