예제 #1
0
def channel_unregister_f(ctx):
    if not isAdmin(ctx.author):
        return -1

    mongoClient = dbClient.getClient()
    mongoClient.DBot.config.delete_one({"channelID": ctx.channel.id})
    return 0
예제 #2
0
파일: DBot.py 프로젝트: drizak/DBot
async def on_message(message):
    # DBot messages
    if message.author == bot.user:
        return 0

    # Other bots messages
    if message.author.bot:
        return 0

    # Only bot admins can get bot response with DMs
    if type(message.channel) == discord.channel.DMChannel:
        if isAdmin(message.author) == False:
            return 0

    # simp excluder
    if message.content.startswith(">") and message.author.id == 399025429605908490:
        await message.channel.send("SIMP")
        return 0

    # Self-invoked commands kills the command execution
    selfInvokedCommand = False
    if await autism_commands.on_message(message) == 0:
        selfInvokedCommand = True

    # Commands
    # Log and then process
    if not selfInvokedCommand:
        log(message)
        await bot.process_commands(message)
예제 #3
0
async def shutdown_f(ctx):
    if not isAdmin(ctx.author):
        return -1

    await ctx.send("Oyasuminasai~")
    dbClient.getClient().close()
    await Bot.getBot().close()
    return 0
예제 #4
0
def channel_register_f(ctx):
    if not isAdmin(ctx.author):
        return -1

    mongoClient = dbClient.getClient()
    mongoClient.DBot.config.delete_many({"type": "channelRegistry"})
    channelRegDoc = {"type": "channelRegistry", "channelID": ctx.channel.id}
    mongoClient.DBot.config.insert_one(channelRegDoc)
    return 0
예제 #5
0
def event_list_f(ctx):
    if not isAdmin(ctx.author):
        return -1

    evManager = EventManager.getEventManager()
    eventList = evManager.getEventList()

    if len(eventList) == 0:
        msg = "{}, There are no registered Events.".format(ctx.author.mention)
    else:
        msg = "Registed Events:\n" + "\n".join(eventList)

    return msg
예제 #6
0
def balance_f(ctx, userMentioned):
    if userMentioned != None:
        if isAdmin(ctx.author):
            targetUser = userMentioned
        else:
            return -1
    else:
        targetUser = ctx.author

    profile = UserProfile.load(targetUser)

    embedTitle = "{}'s Balance".format(profile.user.name)
    embedDescription = economy_fAux.pMoney(profile.ecoBalance)
    embed = discord.Embed(title=embedTitle, description=embedDescription)
    return embed
예제 #7
0
def event_force_f(ctx, eventName, timeToExecution):
    if not isAdmin(ctx.author):
        return -1

    evManager = EventManager.getEventManager()
    event = evManager.getEvent(eventName)

    if event == -1:
        return -2
    else:
        event.setTimeStart(timeToExecution)
        msg = "{}, Event {} will start in {} seconds.".format(
            ctx.author.mention, event.name, timeToExecution)

    return msg
예제 #8
0
def add_f(ctx, mentionedUser):
    if not isAdmin(ctx.author):
        return -1

    mongoClient = dbClient.getClient()
    adminDocCount = mongoClient.DBot.config.count_documents({
        "type":
        "adminRegistry",
        "ID":
        mentionedUser.id
    })
    if adminDocCount == 0:
        adminDoc = {"type": "adminRegistry", "ID": mentionedUser.id}
        mongoClient.DBot.config.insert_one(adminDoc)
        return 0
    else:
        return -2
예제 #9
0
def remove_f(ctx, mentionedUser):
    if not isAdmin(ctx.author):
        return -1

    mongoClient = dbClient.getClient()
    adminDocCount = mongoClient.DBot.config.count_documents({
        "type":
        "adminRegistry",
        "ID":
        mentionedUser.id
    })
    if adminDocCount > 0:
        mongoClient.DBot.config.delete_many({
            "type": "adminRegistry",
            "ID": mentionedUser.id
        })

    if adminDocCount > 0:
        return 0
    else:
        return -2
예제 #10
0
def event_info_f(ctx, eventName):
    if not isAdmin(ctx.author):
        return -1

    evManager = EventManager.getEventManager()
    event = evManager.getEvent(eventName)

    if event == -1:
        msg = "{}, This event is not registered.".format(ctx.author.mention)
    else:
        evLine1 = "Event Information"
        evLine2 = "Name: {}".format(event.name)
        evLine3 = "Status: {}".format(event.status)
        evLine4 = "Start: {}".format(event.timeStart)
        evLine5 = "Duration: {}".format(event.duration)
        evLine6 = "Min. Wait: {}".format(event.minWait)
        evLine7 = "Max. Wait: {}".format(event.maxWait)
        evLines = [
            evLine1, evLine2, evLine3, evLine4, evLine5, evLine6, evLine7
        ]
        msg = "\n".join(evLines)

    return msg
예제 #11
0
def list_f(ctx, args):
    # parse args
    # parse page number
    numbers = [int(arg) for arg in args if arg.isdigit()]
    if len(numbers) > 1:
        return -1
    page = numbers[0] if len(numbers) == 1 else 1

    # parse ranks
    ranksInArgs = [
        arg for arg in args if (arg.upper() in waifu_const.WAIFU_RANKS)
    ]
    ranksQuery = ranksInArgs if len(
        ranksInArgs) > 0 else waifu_const.WAIFU_RANKS

    # parse target user
    mentions = ctx.message.mentions
    if len(mentions) != 0:
        if not isAdmin(ctx.author):
            return -2
        if len(mentions) > 1:
            return -3

        targetUser = mentions[0]
    else:
        targetUser = ctx.author

    # Parse duplicate mode
    duplicateMode = False
    if ("-d" in args) or ("-D" in args) or ("duplicates" in args):
        duplicateMode = True

    # Get waifu profile
    profile = UserProfile.load(ctx.author)

    if len(profile.waifuList) == 0:
        if targetUser == ctx.author:
            return -4
        else:
            return -5

    # Query waifus from DB
    if duplicateMode:
        duplicateIDs = list(profile.waifuGetDuplicateWaifuDict().keys())
        query = {
            "$and": [{
                "MAL_data.charID": {
                    "$in": duplicateIDs
                }
            }, {
                "rank": {
                    "$in": ranksQuery
                }
            }]
        }
    else:
        query = {
            "$and": [{
                "MAL_data.charID": {
                    "$in": list(set(profile.waifuList))
                }
            }, {
                "rank": {
                    "$in": ranksQuery
                }
            }]
        }

    waifuList = list(dbClient.getClient().DBot.waifus.find(query).sort(
        "value", pymongo.DESCENDING))

    if len(waifuList) == 0:
        return -6

    if profile.waifuFavorite is not None:
        waifuFav = waifu_fAux.getWaifu(profile.waifuFavorite)
        embedDescription = "Favorite Waifu: {}{}\nFrom: {}".format(
            waifuFav["name"],
            "" if waifuFav["aliases"] == [] else ", alias {}".format(
                random.choice(waifuFav["aliases"])), waifuFav["animeName"])
        thumbnail_url = random.choice(waifuFav["pictures"])
    else:
        embedDescription = discord.Embed.Empty
        thumbnail_url = random.choice(waifu_const.NO_FAV_WAIFU_URLS)

    embed = discord.Embed(title="{}'s Harem".format(profile.user.name),
                          description=embedDescription)
    waifuStart = waifu_const.WAIFU_LIST_WAIFUS_PER_PAGE * (page - 1)
    waifuEnd = waifuStart + waifu_const.WAIFU_LIST_WAIFUS_PER_PAGE
    for waifu in waifuList[waifuStart:waifuEnd]:
        fieldName = "{}/{} \U0000300C{}\U0000300D: {} [{}]".format(
            waifuList.index(waifu) + 1, len(waifuList), waifu["rank"],
            waifu["name"], waifu["MAL_data"]["charID"])

        fieldValue1 = "Source: {}".format(waifu["animeName"])
        fieldValue2 = "Ranking: {}/{}\nValue: {}".format(
            waifu["ranking"], waifu_fAux.waifuCount(), waifu["value"])
        fieldValues = [fieldValue1, fieldValue2]

        if duplicateMode:
            fieldValue4 = "Count: {}".format(
                profile.waifuList.count(waifu["MAL_data"]["charID"]))
            fieldValues.append(fieldValue4)
        elif profile.waifuList.count(waifu["MAL_data"]["charID"]) > 1:
            fieldValue4 = "Count: {}".format(
                profile.waifuList.count(waifu["MAL_data"]["charID"]))
            fieldValues.append(fieldValue4)

        embed.add_field(name=fieldName,
                        value="\n".join(fieldValues),
                        inline=False)

    embed.add_field(name="Total Waifu Value",
                    value="{}".format(
                        economy_fAux.pMoney(profile.waifuGetTotalValue())),
                    inline=False)

    embed.set_thumbnail(url=thumbnail_url)
    footerText1 = "Waifu Harem page: {} of {}.".format(
        page,
        math.ceil(len(waifuList) / waifu_const.WAIFU_LIST_WAIFUS_PER_PAGE))
    footerText2 = "Search other pages using `>waifu list <page>`"
    embed.set_footer(text=footerText1 + "\n" + footerText2)

    return embed
예제 #12
0
 async def test(self, ctx, *, args):
     if isAdmin(ctx.author):
         await ctx.send(ctx)
         await ctx.send(args)
         await ctx.send(args.split(" "))
예제 #13
0
def addmoney_f(ctx, user, changeAmount):
    if not isAdmin(ctx.author):
        return -1
    else:
        UserProfile.load(user).ecoChangeBalance(changeAmount, forced=True)
        return 0