示例#1
0
async def on_voice_state_update(mem, before, after):
    global client, serverVoices, mysqlHandler, soundsDir

    #Don't care if during startup
    if not doneStartup:
        return
    #Don't do anything if we weren't previously connected
    if before.channel != None:
        server = before.channel.guild.id
    else:
        return
    #Don't do checks if bot is attempting reconnects on its own
    if serverVoices[server].vclient == None:
        return
    #Check for forced disconnects
    if mem.id == client.user.id and after.channel == None:
        print("Disconnect, recreating vserver for " +
              str(before.channel.guild.id))
        try:
            if serverVoices[server].vclient == None:
                await serverVoices[server].vclient.disconnect()
        except Exception as e:
            print(traceback.format_exc())
            print("Issue in voice disconnect?? Recreating anyway")

        serverVoices[server] = vserver.voiceServer(client, mysqlHandler,
                                                   server, soundsDir)
        sys.stdout.flush()
示例#2
0
async def on_guild_join(server):
    global client, serverVoices, head, url, dev, owners, mysqlHandler, configData

    print(f"I joined server: {server.name}")
    serverVoices[server.id] = vserver.voiceServer(client, mysqlHandler,
                                                  server.id,
                                                  configData['soundsdir'])

    if not dev:
        print(
            f"I am now in {str(len(client.guilds))} servers, posting to top.gg"
        )
        body = {'server_count': len(client.guilds)}
        r = requests.post(
            f"https://top.gg/api/bots/{str(client.user.id)}/stats",
            headers=head,
            json=body)
    else:
        print(f"I am now in {str(len(client.guilds))} servers")

    for mem in owners:
        await mem.send(
            f"I joined server: {server.name} - I am now in {str(len(client.guilds))} servers"
        )
    sys.stdout.flush()
示例#3
0
async def on_ready():
    global client, soundsDir, lists, mysqlConnect, serverPunish, nsohandler, nsoTokens, head, cnt, url, dev
    print('Logged in as,', client.user.name, client.user.id)

    cnt = 0
    await client.change_presence(
        game=discord.Game(name="Use !help for directions!", type=0))
    for server in client.servers:
        cnt += 1
        serverVoices[server.id] = vserver.voiceServer(client, mysqlConnect,
                                                      server.id, soundsDir)
        serverPunish[server.id] = punish.Punish(client, server.id,
                                                mysqlConnect)

    if dev == 0:
        print('I am in ' + str(cnt) + ' servers, posting to discordbots.org')
        body = {'server_count': cnt}
        requests.post(url, headers=head, json=body)
    else:
        print('I am in ' + str(cnt) + ' servers')

    print('------')
    sys.stdout.flush()
    nsohandler = nsohandler.nsoHandler(client, mysqlConnect)
    nsoTokens = nsotoken.Nsotoken(client, nsohandler)
    scanAdmins(startup=1)
示例#4
0
async def on_ready():
    global client, soundsDir, mysqlHandler, serverUtils, serverVoices, splatInfo, helpfldr
    global nsoHandler, nsoTokens, head, url, dev, owners, commandParser, doneStartup, acHandler

    if not doneStartup:
        print('Logged in as,', client.user.name, client.user.id)
        #Get owners from Discord team api
        print("Loading owners...")
        theapp = await client.application_info()
        ownerids = [x.id for x in theapp.team.members]
        for mem in client.get_all_members():
            if mem.id in ownerids:
                owners.append(mem)
            if len(owners) == len(ownerids):
                break
    else:
        print('RECONNECT TO DISCORD')

    if dev == 0:
        print('I am in ' + str(len(client.guilds)) +
              ' servers, posting to discordbots.org')
        body = {'server_count': len(client.guilds)}
        requests.post(url, headers=head, json=body)
    else:
        print('I am in ' + str(len(client.guilds)) + ' servers')

    if not doneStartup:
        print("Doing Startup...")
        for server in client.guilds:
            #Don't recreate serverVoices on reconnect
            if server.id not in serverVoices:
                serverVoices[server.id] = vserver.voiceServer(
                    client, mysqlHandler, server.id, soundsDir)

        serverConfig = serverconfig.ServerConfig(mysqlHandler)
        commandParser = commandparser.CommandParser(serverConfig,
                                                    client.user.id)
        serverUtils = serverutils.serverUtils(client, mysqlHandler,
                                              serverConfig, helpfldr)
        nsoTokens = nsotoken.Nsotoken(client, mysqlHandler)
        nsoHandler = nsohandler.nsoHandler(client, mysqlHandler, nsoTokens,
                                           splatInfo)
        acHandler = achandler.acHandler(client, mysqlHandler, nsoTokens)
        await nsoHandler.updateS2JSON()
        await mysqlHandler.startUp()
        print('Done\n------')
        await client.change_presence(
            status=discord.Status.online,
            activity=discord.Game("Use !help for directions!"))
    else:
        print('Finished reconnect')
    doneStartup = True
    sys.stdout.flush()
示例#5
0
async def on_server_join(server):
    global client, soundsDir, serverVoices, serverPunish, head, url, cnt, dev
    print("I joined server: " + server.name)
    serverVoices[server.id] = vserver.voiceServer(client, mysqlConnect,
                                                  server.id, soundsDir)
    serverPunish[server.id] = punish.Punish(client, server.id, mysqlConnect)

    if dev == 0:
        cnt += 1
        print('I am now in ' + str(cnt) +
              ' servers, posting to discordbots.org')
        body = {'server_count': cnt}
        r = requests.post(url, headers=head, json=body)
    else:
        print('I am now in ' + str(cnt) + ' servers')
    sys.stdout.flush()
示例#6
0
async def on_guild_join(server):
    global serverVoices, head, url, dev, owners, mysqlHandler
    print("I joined server: " + server.name)
    serverVoices[server.id] = vserver.voiceServer(client, mysqlHandler,
                                                  server.id, soundsDir)

    if dev == 0:
        print('I am now in ' + str(len(client.guilds)) +
              ' servers, posting to discordbots.org')
        body = {'server_count': len(client.guilds)}
        r = requests.post(url, headers=head, json=body)
    else:
        print('I am now in ' + str(len(client.guilds)) + ' servers')

    for mem in owners:
        await mem.send("I joined server: " + server.name + " with " +
                       str(len(server.members)) + " members - I am now in " +
                       str(len(client.guilds)) + " servers with " +
                       str(len(set(client.get_all_members()))) +
                       " total members")
    sys.stdout.flush()
示例#7
0
async def on_ready():
    global client, mysqlHandler, serverUtils, serverVoices, splatInfo, configData, ownerCmds
    global nsoHandler, nsoTokens, head, dev, owners, commandParser, doneStartup, acHandler, stringCrypt

    if not doneStartup:
        print('Logged in as,', client.user.name, client.user.id)

        #This is needed due to no prsence intent, prod bot needs to find the devs in its primary server
        print(
            f"Chunking home server ({str(configData['home_server'])}) to find owners"
        )
        await client.get_guild(int(configData['home_server'])).chunk()

        #Get owners from Discord team api
        print("Loading owners...")
        theapp = await client.application_info()
        if theapp.team:
            ownerids = [x.id for x in theapp.team.members]
        else:
            ownerids = [theapp.owner.id]

        for mem in client.get_all_members():
            if mem.id in ownerids:
                owners.append(mem)
                print(f"Loaded owner: {str(mem.name)}")
            if len(owners) == len(ownerids):
                break
    else:
        print('RECONNECT TO DISCORD')

    if not dev:
        print(f"I am in {str(len(client.guilds))} servers, posting to top.gg")
        body = {'server_count': len(client.guilds)}
        requests.post(f"https://top.gg/api/bots/{str(client.user.id)}/stats",
                      headers=head,
                      json=body)
    else:
        print(f"I am in {str(len(client.guilds))} servers")

    if not doneStartup:
        print("Doing Startup...")
        for server in client.guilds:
            if server.id not in serverVoices:
                serverVoices[server.id] = vserver.voiceServer(
                    client, mysqlHandler, server.id, configData['soundsdir'])

        serverConfig = serverconfig.ServerConfig(mysqlHandler)
        commandParser = commandparser.CommandParser(serverConfig,
                                                    client.user.id)
        ownerCmds = ownercmds.ownerCmds(client, mysqlHandler, commandParser,
                                        owners)
        serverUtils = serverutils.serverUtils(client, mysqlHandler,
                                              serverConfig, configData['help'])
        nsoTokens = nsotoken.Nsotoken(client, mysqlHandler,
                                      configData.get('hosted_url'),
                                      stringCrypt)
        nsoHandler = nsohandler.nsoHandler(client, mysqlHandler, nsoTokens,
                                           splatInfo,
                                           configData.get('hosted_url'))
        acHandler = achandler.acHandler(client, mysqlHandler, nsoTokens,
                                        configData)
        await mysqlHandler.startUp()
        mysqlSchema = mysqlschema.MysqlSchema(mysqlHandler)
        await mysqlSchema.update()
        await nsoTokens.migrateTokensTable()

        await nsoHandler.updateS2JSON()
        await nsoTokens.updateAppVersion()
        print('Done\n------')
        await client.change_presence(
            status=discord.Status.online,
            activity=discord.Game("Check Slash Commands!"))
    else:
        print('Finished reconnect')
    doneStartup = True

    sys.stdout.flush()