Esempio n. 1
0
 async def tldr(self, ctx, *prompt: str):
     user_id, user_name = user_parse(ctx)
     usage = len(list("".join(prompt)))
     if usage == 0:
         raise EmptyPromptError
     answer = await self.__api.tldr(prompt, language=self.language)
     return await ctx.send(discord.utils.escape_mentions(answer))
Esempio n. 2
0
 async def credit(self, ctx):
     user_id, user_name = user_parse(ctx)
     guild_id = ctx.guild.id
     today_usage, _, _ = self.__db.get_user_settings(guild_id, user_id)
     _, _, _, _, allowance = self.__db.get_server_settings(guild_id)
     return await ctx.send(
         "{}, your remaining daily allowance is: {}.".format(
             user_name, allowance - today_usage))
Esempio n. 3
0
 async def settings(self, ctx):
     user_id, user_name = user_parse(ctx)
     guild_id = ctx.guild.id
     _, language, temperature = self.__db.get_user_settings(
         guild_id, user_id)
     return await ctx.send(
         "{}, your language is set to: {} and temperature is set to: {}".
         format(user_name, language, temperature))
Esempio n. 4
0
 async def length(self, ctx, length: int):
     user_id, user_name = user_parse(ctx)
     guild_id = ctx.guild.id
     owner_id, vips, _, old_length, allowance = self.__db.get_server_settings(
         guild_id)
     if user_id != owner_id:
         raise NotAdminError
     self.__db.update_server_length(guild_id, length)
     return await ctx.send(
         "Successfully updated response length to {}".format(length))
Esempio n. 5
0
 async def allowance(self, ctx, allowance: int):
     user_id, user_name = user_parse(ctx)
     guild_id = ctx.guild.id
     owner_id, vips, _, length, old_allowance = self.__db.get_server_settings(
         guild_id)
     if user_id != owner_id:
         raise NotAdminError
     self.__db.update_server_allowance(guild_id, allowance)
     return await ctx.send(
         "Successfully updated member allowance to {}".format(allowance))
Esempio n. 6
0
 async def remove_vip(self, ctx, *, member: discord.Member):
     user_id, user_name = user_parse(ctx)
     guild_id = ctx.guild.id
     owner_id, vips, _, length, allowance = self.__db.get_server_settings(
         guild_id)
     if user_id != owner_id:
         raise NotAdminError
     member_id, member_name = member.id, member.display_name
     self.__db.remove_vip(guild_id, member_id)
     return await ctx.send(
         "Successfully removed {} from vips.".format(member_name))
Esempio n. 7
0
 async def language(self, ctx, lang: str):
     user_id, user_name = user_parse(ctx)
     guild_id = ctx.guild.id
     possible_languages = list(language_map.keys())
     if lang not in possible_languages:
         return await ctx.send(
             "{}, chosen language must be within: {}".format(
                 user_name, possible_languages))
     today_usage, language, temperature = self.__db.get_user_settings(
         guild_id, user_id)
     self.__db.update_user_language(guild_id, user_id, lang)
     return await ctx.send(
         "Sucessfully updated your settings, {}. Old language: {}, New language: {}"
         .format(user_name, language, lang))
Esempio n. 8
0
 async def config(self, ctx):
     user_id, user_name = user_parse(ctx)
     guild_id = ctx.guild.id
     owner_id, vips, _, length, allowance = self.__db.get_server_settings(
         guild_id)
     if user_id != owner_id:
         raise NotAdminError
     length_str = "# Length: {}\n".format(length)
     allowance_str = "# Allowance: {}\n".format(allowance)
     vips_str = """# Vips\n"""
     for i in range(len(vips)):
         vips_str += "{} - {}\n".format(i + 1, vips[i])
     vips_str += "Note: Owners are automatically assigned a vip role."
     return await ctx.send(length_str + allowance_str + vips_str)
Esempio n. 9
0
    async def setup(self, ctx):
        user_id, user_name = user_parse(ctx)
        owned_servers = self.__db.find_owned_servers(user_id)
        if not len(owned_servers) > 0:
            await ctx.send(
                "You don't seem to own any servers that i'm on. If you think this is a mistake, kick the "
                "bot and add it again.")
            return
        if len(owned_servers) > 1:
            await ctx.send(
                "For the time being you cannot add me to more than one server. But the developers are "
                "working on it.")
            return
        await ctx.send(
            "Important note: For this bot to function and process requests, it has to save your api key in "
            "a database. This means that if the bad guys somehow access it, they can use your token and "
            "even cause incurring charges. We cannot be held responsible for that and suggest you to host "
            "on your own. You can do so by visiting the public repo on github("
            "github.com/e4c6/DiscordGPT-3). If that's not a concern for "
            "you, feel free to proceed. If you ever doubt something is going fishy, you should quickly "
            "regenerate your api token through the developer portal on beta.openai.com."
        )
        owned_server = owned_servers[0]
        server_id, server_name = owned_server["server_id"], owned_server[
            "server_name"]
        await ctx.send(
            "Hi {}, i see that you're the owner of {}. Now please send me your OpenAI api key within 60 "
            "seconds. (and "
            "nothing else).\nIt should be visible to you on https://beta.openai.com/account/api-keys."
            .format(user_name, server_name))

        def check_token(m):
            return m.channel == ctx.channel

        msg = await bot.wait_for("message", check=check_token, timeout=60)
        if not msg.content[0:3] == "sk-":
            await ctx.send(
                "Your api token should start with the characters sk-. You can restart this process when "
                "you find it.")
            return
        if len(msg.content) > 50:
            await ctx.send(
                "Your key seems abnormally long... You can restart this process when "
                "you find the right key.")
            return
        self.__db.set_server_token(server_id, msg.content)
        await ctx.send(
            "Successfully set the token, enjoy! If you like this bot, please consider donating to us via "
            "our BTC address: 14ozvJYfChmiXwqhfzH4yCqcYR7gzwfVYT")
Esempio n. 10
0
 async def temperature(self, ctx, temp: float):
     user_id, user_name = user_parse(ctx)
     guild_id = ctx.guild.id
     if not 0 <= temp <= 1:
         return await ctx.send(
             "{}, chosen temperature must equal or be within the range of 0 and 1. (e.g. 0.3) "
             "You can read more about temperature on "
             "https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277 or "
             "https://beta.openai.com/docs/api-reference/create-completion-via-get."
             .format(user_name))
     today_usage, language, temperature = self.__db.get_user_settings(
         guild_id, user_id)
     self.__db.update_user_temperature(guild_id, user_id, temp)
     return await ctx.send(
         "Sucessfully updated your settings, {}. Old temperature: {}, New temperature: {}"
         .format(user_name, temperature, temp))
Esempio n. 11
0
 async def sentiment(self, ctx, *prompt: str):
     usage = len(list("".join(prompt)))
     if usage == 0:
         raise EmptyPromptError
     user_id, user_name = user_parse(ctx)
     guild_id = ctx.guild.id
     today_usage, language, temperature = self.__db.get_user_settings(
         guild_id, user_id)
     owner_id, vips, token, length, allowance = self.__db.get_server_settings(
         guild_id)
     if usage + today_usage > allowance and user_id not in vips:
         raise CreditExhaustedError
     answer = await self.__api.sentiment(prompt,
                                         api_key=token,
                                         language=language)
     self.__db.increment_member_usage(guild_id, user_id, usage)
     return await ctx.send(discord.utils.escape_mentions(answer))
Esempio n. 12
0
 async def ask_owner(ctx):
     user_id, user_name = user_parse(ctx)
     await ctx.send(
         "{}, if you know the passcode to enable me write: !passcode the_passcode."
         .format(user_name))
Esempio n. 13
0
 async def not_admin_warning(ctx):
     user_id, user_name = user_parse(ctx)
     await ctx.send(
         "{}, this command is only usable by admins.".format(user_name))
Esempio n. 14
0
 async def credit_warning(ctx):
     user_id, user_name = user_parse(ctx)
     await ctx.send(
         "{}, your daily allowance is over. :cry:".format(user_name))