Untitled

                Never    
import discord
import random
import pickle
import asyncio
from random import shuffle
from discord.ext import commands
bot = commands.Bot(command_prefix='!!', description='mafia bot')
@bot.event
async def on_ready():
    global gameAct
    gameAct = []
    print('Logged in as')
    print(bot.user.name)

@bot.event
async def on_message(message):
    print(message.channel)
    global gameAct
    print(gameAct)
    for i in gameAct:
        if str(i) == str(message.channel):
            fileN = str(i) + '.game'
            try:
                players = pickle.load(open(fileN, "rb"))
            except FileNotFoundError:
                print('noo good')
                return
            print(players['play'])
            for i in players['play']:
                if str(i) == str(message.author):
                    return
            await bot.delete_message(message)
    await bot.process_commands(message)
    
@bot.command(pass_context=True)
async def testercle(ctx, namerZ: str):
    namerZa = namerZ
    nN = random.randint(1, 999)
    if namerZa is None:
        nN = nN + 1
        namerZa = str(channel.name() + str(nN))
    server = ctx.message.server
    await bot.create_channel(server, name=namerZa)

@bot.command(pass_context=True)
async def testtt(ctx):
    await bot.send_typing(ctx.message.channel)

	
@bot.command(pass_context=True)
async def hello(ctx, userName: discord.Member = None):
    if userName is None:
        userName = ctx.message.author
    await bot.say('Hello, {0}!'.format(userName))

@bot.group(pass_context=True)
async def game(ctx):
    if ctx.invoked_subcommand is None:
        await bot.say('specify game type and gamename ie: "!!game normal game1"')

    
    
    
@game.command(pass_context=True)
async def normal(ctx, playNm: str):
    global gameOn
    await bot.send_typing(ctx.message.channel)
    gameOn = True
    gameMa = {}
    gameAu = ctx.message.author
    if playNm is None:
        playNm = gameAu
    gameMa['name'] = playNm
    gameMa['host'] = gameAu
    gameMa['open'] = True
    gameMa['run'] = False
    gameMa['play'] = []
    gameMa['team'] = []
    gameMa['roles'] = {}
    await bot.say('{} is starting a mafia game named {} it will begin after they type !!start'.format(gameAu, playNm))
    fileN = playNm + '.game'
    pickle.dump(gameMa, open(fileN, "wb"))
    await bot.say('this is a test. Type !!join {} to join'.format(playNm))


@bot.command(pass_context=True)
async def join(ctx, joiNa: str, userName: discord.Member = None):
    if joiNa is None:
        await bot.say('You need to type the game name eg. !!join game1')
        return
    fileN = joiNa + '.game'
    try:
        gameMa = pickle.load(open(fileN, "rb"))
    except FileNotFoundError:
        await bot.say('That game was not found either you misspelled the name or it does not exist or i broke the program')
        return
    if userName is None:
        userName = ctx.message.author
    
    #if userName in gameMa['play']:
     #   await bot.say('you have already joined this game!')
      #  pickle.dump(gameMa, open(fileN, "wb"))
       # return
    if gameMa['open'] is True:
        gameMa['play'].append(userName)
        await bot.say('@{} is playing in game <{}> type !!join {} to play with them.'.format(userName, gameMa['name'], gameMa['name']))
        print(gameMa['play'])
        pickle.dump(gameMa, open(fileN, "wb"))
    else:
        await bot.say('that game is not open for signups, !!game normal <game name> to start your own!')
        pickle.dump(gameMa, open(fileN, "wb"))

@bot.command(pass_context=True)
async def start(ctx, gameNa: str):
    global gameAct
    if gameNa is None:
        await bot.say('start what game?')
        return
    fileN = gameNa + '.game'
    try:
        gameMa = pickle.load(open(fileN, "rb"))
    except FileNotFoundError:
        await bot.say('no game by that name, partner')
        return
    starterN = ctx.message.author
    if gameMa['host'] != starterN:
        await bot.say('not your game, pal')
        return
    await bot.send_typing(ctx.message.channel)
    playRs = 0
    if gameMa['open'] is False:
        await bot.say('that game has already started or is otherwise labeled as closed')
        return
    for i in range(len(gameMa['play'])):
        playRs += 1
    if playRs <= 3:
        await bot.say('your game is a bit small try for 4 or more players. the more the better!')
        return
    print(playRs)
    await bot.say('game <{}> is no longer open for signups and is starting with {} players. Please wait as I create the game.'.format(gameMa['name'], playRs))
    gameMa['open'] = False
    await bot.send_typing(ctx.message.channel)
    playMs = round(playRs/4)
    print(playMs)
    mafT = playMs
    playTs = playRs - playMs
    print(playTs)
    mafPlay = []
    roles = []
    if playMs >= 3:
        roles.append('Godfather')
        roles.append('Cop')
        playMs -= 1
        playTs -= 1
    if playMs >= 2:
        roles.append('Vigilante')
        playTs -= 1
    for i in range(playMs):
        roles.append('Goon')
    for i in range(playTs):
        roles.append('Townie')
    print(roles)
    shuffle(roles)
    print(roles)
    gameP1 = gameMa['play']
    print(gameMa['play'])
    gameP = gameP1
    shuffle(gameP)
    while gameP:
        if roles[-1] == 'Goon' or 'Godfather':
            gameMa['team'].append(gameP[-1])
            print(gameMa['team'])
        await bot.send_message(gameP.pop(), 'you have received the role: {}'.format(roles.pop()))
    mafPlay1 = gameMa['team']
    if mafT > 1:
        for x in range(len(gameMa['team'])):
            for y in range(len(mafPlay1)):
                await bot.send_message(mafPlay1[x-1], 'the mafia: {}'.format(mafPlay1[y-1]))
    namerZa = gameMa['name']
    server = ctx.message.server
    await bot.create_channel(server, name=namerZa)
    gameAct.append(namerZa)
    print(gameAct)
    print(gameMa['play'])
    pickle.dump(gameMa, open(fileN, "wb"))
    await bot.say('Roles are out, channel created, did it work?')
        

    
	
bot.run('MzYzODM2NjM4MDQ2MDYwNTQ0.DLHCJQ.JrM19e_8vnpaX1mdVi0BO_9tZ4o')

Raw Text