예제 #1
0
 async def answers_addwordtolist(self, ctx, listName, word):
     guildconf = await guildsave.returnGuildJson(ctx,
                                                 str(ctx.message.guild.id))
     for x in guildconf["AnswerList"]:
         if x["NAME"].lower() == listName.lower():
             val = {'a': word}
             x["WORDS"].append(val['a'])
             guildsave.saveDataToJson(
                 str(ctx.message.guild.id), guildconf)
             await ctx.send("Added!")
             return
     await ctx.send("The list doesn't exist!")
예제 #2
0
    async def answers_addjson(self, ctx, *args):
        try:
            l = ' '.join(args)
            jfile = json.loads(l)
            guildconf = await guildsave.returnGuildJson(ctx,
                                                        str(ctx.message.guild.id))

            guildconf["AnswerList"].append(jfile)

            guildsave.saveDataToJson(
                str(ctx.message.guild.id), guildconf)

            await ctx.send("Added json!")
            return
        except:
            await ctx.send("Error parsing json!")
예제 #3
0
    async def answers_createlist(self, ctx, listName, listType):
        guildconf = await guildsave.returnGuildJson(ctx,
                                                    str(ctx.message.guild.id))

        for x in guildconf["AnswerList"]:
            if x["NAME"].lower() == listName.lower():
                await ctx.send("List already exists!")
                return

        obj = ext.word_answering_random(
            listName, listType.upper(), [], [])

        guildconf["AnswerList"].append(obj.toDict())

        guildsave.saveDataToJson(str(ctx.message.guild.id), guildconf)

        await ctx.send("List created!")
예제 #4
0
    async def answers_removelist(self, ctx, listName, usure):
        if usure != "I am very sure of this!":
            await ctx.send("In the parameter 'usure', please say 'I am very sure of this!'")
            return

        guildconf = await guildsave.returnGuildJson(ctx,
                                                    str(ctx.message.guild.id))

        for i in range(0, len(guildconf["AnswerList"])):
            x = guildconf["AnswerList"][i]
            if x["NAME"].lower() == listName.lower():
                del guildconf["AnswerList"][i]

                guildsave.saveDataToJson(str(ctx.message.guild.id), guildconf)
                await ctx.send("Removed list!")
                return

        await ctx.send("List doesnt exist!")
예제 #5
0
    async def conf_setparameter(self, ctx, parameterName, parameterCategory,
                                parameterValue):
        guildconf = await guildsave.returnGuildJson(ctx,
                                                    str(ctx.message.guild.id))

        try:
            parameterName = parameterName.lower()
            parameterCategory = parameterCategory.lower()
            changedParameter = False

            if parameterCategory == "switches":
                guildconf["userConfig"][parameterCategory][parameterName] = (
                    parameterValue.lower() == "true")
                changedParameter = True

            if changedParameter == False:
                await ctx.send("Error changing parameters!")
                return

            guildsave.saveDataToJson(ctx.message.guild.id, guildconf)
            await ctx.send("Changed parameter!")
        except:
            await ctx.send("Error changing parameters!")
예제 #6
0
 async def answers_removeat(self, ctx, listName, deleteWhat, index):
     guildconf = await guildsave.returnGuildJson(ctx,
                                                 str(ctx.message.guild.id))
     if deleteWhat.upper() == "WORDS":
         for x in guildconf["AnswerList"]:
             if x["NAME"].lower() == listName.lower():
                 del x["WORDS"][int(index)]
                 guildsave.saveDataToJson(
                     str(ctx.message.guild.id), guildconf)
                 await ctx.send("Removed word!")
                 return
         await ctx.send(f"List '{listName}' doesn't exist!")
         return
     if deleteWhat.upper() == "ANSWERS":
         for x in guildconf["AnswerList"]:
             if x["NAME"].lower() == listName.lower():
                 del x["ANSWERS"][int(index)]
                 guildsave.saveDataToJson(
                     str(ctx.message.guild.id), guildconf)
                 await ctx.send("Removed answer!")
                 return
         await ctx.send(f"List '{listName}' doesn't exist!")
         return
     await ctx.send(f"I don't know what '{deleteWhat}' is!")
예제 #7
0
async def on_message(message):
    if message.author == bot.user:
        return

    # COMMAND HANDLING
    author_colored = colored((message.author), "red")
    if len(message.content) > 0:
        if message.content[0] == '$':
            print(f"{author_colored} -> {message.content}")

    # CHECK IF GUILD PERMITS THE COMMAND
    if message.guild == None:
        return

    guildsettings = await guildsave.returnGuildJson(message.channel,
                                                    str(message.guild.id))
    cmd_category = message.content[1:].split('.')

    if cmd_category[0] in guildsettings["userConfig"]["switches"]:
        isenabled = guildsettings["userConfig"]["switches"][cmd_category[0]]

        if isenabled == False:
            await message.channel.send("Guild has this command disabled!")
            return

    await bot.process_commands(message)

    # RANDOM_ANSWERS TEST!
    if int(guildsettings["LastCheckTime"]
           ) >= time.time() - guildsettings["AnswerCooldown"]:
        # print("wordchecking is on cooldown!")
        return

    if len(message.content) <= 1:
        return

    if message.content[0] == '$':
        return

    guildsettings["LastCheckTime"] = time.time()

    guildsave.saveDataToJson(str(message.guild.id), guildsettings)

    random_answers = []
    for x in guildsettings["AnswerList"]:
        a = ext.word_answering_random(x["NAME"], x["TYPE"], x["WORDS"],
                                      x["ANSWERS"])
        random_answers.append(a)

    for ra in random_answers:
        a = ra.checkword(message.content)

        if a != None:
            # a = (a.decode("raw_unicode_escape").encode(
            # 'utf-16', 'surrogatepass').decode('utf-16'))
            #a = emojilist.replaceEmojiInString(a)

            if ra.returnType().upper() == "TEXT":
                await message.channel.send(a.format(message.author.mention))
                return
            if ra.returnType().upper() == "MEDIA":
                await message.channel.send(file=discord.File(
                    f"./guilds/{message.guild.id}/uploads/{a}"))
                return
            if ra.returnType().upper() == "TEXTNMEDIA":
                if ext.isAdmitedMediaType(mediatypes, a):
                    await message.channel.send(file=discord.File(
                        f"./guilds/{message.guild.id}/uploads/{a}"))
                else:
                    await message.channel.send(
                        a.format(author=message.author.mention))
                return
            if ra.returnType().upper() == "REACTION":
                await message.add_reaction(a)
                return