Ejemplo n.º 1
0
async def clearwarns(ctx, *, user):
    kaomod = False
    for role in ctx.author.roles:
        if role.id == 694533853951295590:
            kaomod = True
    if not kaomod:
        if ctx.author.guild_permissions.manage_messages:
            kaomod = True
        if ctx.author.guild_permissions.administrator:
            kaomod = True
        if ctx.message.author.id == ownerid:
            kaomod = True
    if not kaomod:
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["permission_denied"])
        return
    try:
        userid = ctx.message.mentions[0].id
        userwarns.pop(str(userid))
    except:
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["specify_user"])
        return
    warned_user = f'{ctx.message.mentions[0].name}#{ctx.message.mentions[0].discriminator}'
    await ctx.send(languages[guild_language.setdefault(str(
        ctx.guild.id), "en")]["clearwarns_success"].format(user=warned_user))
    with open('warns.json', 'w') as json_file:
        json.dump(userwarns, json_file)
    if use_postgres: backup()
Ejemplo n.º 2
0
async def addresponsedynamic(ctx, *, response):
    kaomod = False
    for role in ctx.author.roles:
        if role.id == 694533853951295590:
            kaomod = True
    if not kaomod:
        if ctx.author.guild_permissions.manage_messages:
            kaomod = True
        if ctx.author.guild_permissions.administrator:
            kaomod = True
        if ctx.message.author.id == ownerid:
            kaomod = True
    if not kaomod:
        await ctx.send(f'Nemate dozvolu!' if guild_language.setdefault(
            str(ctx.guild.id), False) else f'You don\'t have permissions')
        return
    key, value = response.split(';')
    while key[0] == ' ':
        key = key[1:]
    while value[0] == ' ':
        value = value[1:]
    if str(ctx.guild.id) not in responses:
        responses[str(ctx.guild.id)] = {"static": {}, "dynamic": {}}
    responses[str(ctx.guild.id)]["dynamic"].update({key.lower(): value})
    with open('responses.json', 'w') as json_file:
        json.dump(responses, json_file)
    await ownerdm.send(file=discord.File('responses.json'))
    await ctx.send(languages[guild_language.setdefault(str(
        ctx.guild.id), "en")]["dynamic_response_added"].format(value=value,
                                                               key=key))
    if use_postgres: backup()
Ejemplo n.º 3
0
async def changelang(ctx, language=None):
    global guild_language
    if ctx.message.author.id == ownerid or ctx.author.guild_permissions.manage_messages or ctx.author.guild_permissions.administrator:
        pass
    else:
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["permission_denied"])
        return
    if language == None:
        guild_language[str(ctx.guild.id)] = "hr" * (guild_language[str(
            ctx.guild.id)] == "en") + "en" * (guild_language[str(ctx.guild.id)]
                                              == "hr")
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["language_change"])
    if language in languages:
        guild_language[str(ctx.guild.id)] = str(language)
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["language_change"])
    else:
        await ctx.send(language_not_supported)
        return
    try:
        with open('guild_language.json', 'w') as json_file:
            json.dump(guild_language, json_file)
        await ownerdm.send('guild_language.json updated')
    except:
        await ownerdm.send('guild_language.json update error')
    if use_postgres: backup()
Ejemplo n.º 4
0
async def memesource(ctx, *, subreddit):
    query = subreddit
    sub = query.replace(' ', '')
    if sub.startswith("r/"):
        sub = sub[2:]
    if sub.lower() == "none":
        try:
            subsettings.pop(str(ctx.message.author.id))
        except:
            pass
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["default_sub_removed"])
        with open('subsettings.json', 'w') as json_file:
            json.dump(subsettings, json_file)
        if use_postgres: backup()
        return
    try:
        if reddit.subreddit(sub).over18:
            pass
        subsettings.update({str(ctx.message.author.id): str(sub)})
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["default_sub_success"].format(sub=sub))
    except:
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["default_sub_fail"])
    with open('subsettings.json', 'w') as json_file:
        json.dump(subsettings, json_file)
    if use_postgres: backup()
Ejemplo n.º 5
0
async def wikilang(ctx, language=None):
    if language == None:
        deflang = str(
            wikipedia_language.setdefault(
                str(ctx.message.author.id),
                guild_language.get(str(ctx.guild.id), "en")))
        await ctx.send("Language is {short} - {long}".format(
            short=deflang, long=wikipedia.languages()[deflang]))
        return
    query = language.lower()
    if query in wikipedia.languages():
        wikipedia_language.update({str(ctx.message.author.id): str(query)})
        lg = wikipedia.languages()[query]
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["wikilang_success"].format(query=query,
                                                                 lg=lg))
    else:
        defaultlanguage = wikipedia_language.setdefault(
            str(ctx.message.author.id),
            guild_language.setdefault(str(ctx.guild.id), "en"))
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["wikilang_error"].format(
                defaultlang=defaultlanguage,
                defaultlg=wikipedia.languages()[defaultlanguage]))
    with open('wikipedia_language.json', 'w') as json_file:
        json.dump(wikipedia_language, json_file)
    if use_postgres: backup()
Ejemplo n.º 6
0
async def warn(ctx, *, args):
    warnovi = []
    kaomod = False
    try:
        person, reason = args.split('>', maxsplit=1)
        if reason == '':
            await ctx.send(languages[guild_language.setdefault(
                str(ctx.guild.id), "en")]["specify_reason"])
            return
        while reason[0] == ' ':
            reason = reason[1:]
    except:
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["specify_user"])
        return
    for role in ctx.author.roles:
        if role.id == 694533853951295590:
            kaomod = True
    if not kaomod:
        if ctx.author.guild_permissions.manage_messages:
            kaomod = True
        if ctx.author.guild_permissions.administrator:
            kaomod = True
        if ctx.message.author.id == ownerid:
            kaomod = True
    if not kaomod:
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["permission_denied"])
        return
    try:
        ime = f'{ctx.message.mentions[0].name}#{ctx.message.mentions[0].discriminator}'
    except:
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["specify_user"])
        return
    userid = ctx.message.mentions[0].id
    try:
        warnovi = userwarns.pop(str(userid))
    except:
        warnovi = []
    finally:
        warnovi += reason.split("\n")
        userwarns.update({str(userid): warnovi})
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["warn_success"].format(ime=ime,
                                                             reason=reason))
        await client.get_user(userid).send(languages[guild_language.setdefault(
            str(ctx.guild.id),
            "en")]["warned"].format(guild_name=ctx.guild.name, reason=reason))
        with open('warns.json', 'w') as json_file:
            json.dump(userwarns, json_file)
        if use_postgres: backup()
Ejemplo n.º 7
0
async def removeresponse(ctx, *, response):
    if ctx.message.author.id == ownerid or ctx.author.guild_permissions.manage_messages or ctx.author.guild_permissions.administrator:
        pass
    else:
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["permission_denied"])
        return
    if ctx.message.content.startswith("?rrd"):
        try:
            key = list(
                responses.get(str(
                    ctx.guild.id), {"dynamic": {}})["dynamic"].keys())[list(
                        responses.get(str(ctx.guild.id),
                                      {"dynamic": []
                                       })["dynamic"].values()).index(response)]
        except ValueError:
            await ctx.send(languages[guild_language.setdefault(
                str(ctx.guild.id),
                "en")]["response_not_found"].format(response=response))
            return
        if responses[str(ctx.guild.id)]["dynamic"].pop(key) == response:
            await ctx.send(languages[guild_language.setdefault(
                str(ctx.guild.id),
                "en")]["dynamic_response_removed"].format(value=response,
                                                          key=key))
    elif ctx.message.content.startswith("?rrs"):
        try:
            key = list(
                responses.get(str(
                    ctx.guild.id), {"static": {}})["static"].keys())[list(
                        responses.get(str(ctx.guild.id),
                                      {"static": {}
                                       })["static"].values()).index(response)]
        except ValueError:
            await ctx.send(languages[guild_language.setdefault(
                str(ctx.guild.id),
                "en")]["response_not_found"].format(response=response))
            return
        if responses[str(ctx.guild.id)]["static"].pop(key) == response:
            await ctx.send(languages[guild_language.setdefault(
                str(ctx.guild.id),
                "en")]["static_response_removed"].format(value=response,
                                                         key=key))
    else:
        await ctx.send(languages[guild_language.setdefault(
            str(ctx.guild.id), "en")]["specify_response"])
        return
    with open('responses.json', 'w') as json_file:
        json.dump(responses, json_file)
    if use_postgres: backup()
Ejemplo n.º 8
0
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')
    await client.change_presence(activity=discord.Game(
        name='wikibot.tech | ?help'))
    global ownerdm
    ownerdm = client.get_user(ownerid)
    try:
        global guild_language
        with open('guild_language.json') as json_file:
            guild_language = json.load(json_file)
        print(guild_language)
        await ownerdm.send('guild_language.json loaded')
        try:
            await ownerdm.send(f'guild_language:\n```{guild_language}```')
        except:
            await ownerdm.send(f'guild_language:\n```file too large```')
    except:
        await ownerdm.send('Exception, generating new guild_language.json')
        for guild in client.guilds:
            if guild.id == 601663624175419412:
                guild_language.update({str(guild.id): "hr"})
            else:
                guild_language.update({str(guild.id): default_lang})
        with open('guild_language.json', 'w') as json_file:
            json.dump(guild_language, json_file)
    try:
        global wikipedia_language
        with open('wikipedia_language.json') as json_file:
            wikipedia_language = json.load(json_file)
        await ownerdm.send('wikipedia_language.json loaded')
        try:
            await ownerdm.send(
                f'wikipedia_language:\n```{wikipedia_language}```')
        except:
            await ownerdm.send(f'wikipedia_language:\n```file too large```')
    except:
        await ownerdm.send('wikipedia_language.json not found')
    try:
        global subsettings
        with open('subsettings.json') as json_file:
            subsettings = json.load(json_file)
        await ownerdm.send('subsettings.json loaded')
        try:
            await ownerdm.send(f'subsettings:\n```{subsettings}```')
        except:
            await ownerdm.send(f'subsettings:\n```file too large```')
    except:
        await ownerdm.send('subsettings.json not found')
    try:
        global userwarns
        with open('warns.json') as json_file:
            userwarns = json.load(json_file)
        await ownerdm.send('warns.json loaded')
    except:
        await ownerdm.send('warns.json not found')
    if use_topgg:
        TopGG.setup(client=client)
        await ownerdm.send('Setting up TopGG cog')
    await ownerdm.send('Done')
    if use_postgres: backup()
    print("Done")