Skip to content

Commit

Permalink
DALL-E integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythonic-Rainbow committed Jan 8, 2024
1 parent c725ee6 commit b121a34
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
6 changes: 4 additions & 2 deletions DimBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ async def bs(ctx: commands.Context, server: int):
async def changelog(ctx):
ch = 666431254312517633 if dimsecret.debug else 977778385247944754
await bot.get_channel(ch).send(f"""# __{missile.ver} (<t:{last_modified}>)__
`Project Hyperstellar` is now a separate project. Donation events are sent by another bot.
Added `d.de` and `d.de3`: OpenAI DALL-E image generation.
__PLEASE DO NOT SPAM THE COMMAND IT COSTS ME A FUCK TON OF MONEY!!!!!__
""")


Expand Down Expand Up @@ -500,7 +501,8 @@ async def ready_tasks():
bot.add_cog(Diminator(bot))
# bot.add_cog(SkyBow(bot))
bot.add_cog(Nene(bot))
bot.add_cog(Hyperstellar(bot))
if not dimsecret.debug:
bot.add_cog(Hyperstellar(bot))
await bot.wait_until_ready()
bot.add_cog(tribe.Hamilton(bot))
psutil.cpu_percent(percpu=True)
Expand Down
19 changes: 18 additions & 1 deletion missile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import dimsecret

__lvl__ = logging.DEBUG if dimsecret.debug else logging.INFO
ver = '0.10.25.1'
ver = '0.10.25.2'


def get_logger(name: str) -> logging.Logger:
Expand Down Expand Up @@ -135,6 +135,7 @@ async def check(ctx):

def bot_has_perm(**kwargs):
"""Checks whether DimBot has perms in that guild channel"""

async def check(ctx):
remote = ctx.guild.me.permissions_in(ctx.channel)
has = remote.is_superset(discord.Permissions(**kwargs))
Expand Down Expand Up @@ -177,6 +178,22 @@ async def no_guild():
return commands.check(check)


def cooldown_no_rainbow(rate, per, typee=commands.BucketType.default):
def check(ctx: commands.Context):
if not hasattr(ctx.command, '_gay_bucket'):
ctx.command._buckets = commands.CooldownMapping(commands.Cooldown(rate, per, typee))
ctx.command._gay_bucket = None
if ctx.author.id == ctx.bot.owner_id:
if ctx.command._buckets._cooldown:
ctx.command._gay_bucket = ctx.command._buckets._cooldown
ctx.command._buckets._cooldown = None
elif ctx.command._buckets._cooldown is None:
ctx.command._buckets._cooldown = ctx.command._gay_bucket
return True

return commands.check(check)


class UserStore:
"""Stores user specific objects used by DimBot"""

Expand Down
19 changes: 19 additions & 0 deletions nene.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,22 @@ async def delete(self, ctx):
await self.bot.sql.remove_translator_convo(self.bot.db, creator=ctx.author.id, ch=ctx.channel.id)
await ctx.reply('Done')

@commands.command(brief='DALL-E 2 image generation')
@missile.cooldown_no_rainbow(1, 600, commands.BucketType.user)
async def de(self, ctx, *, prompt: str):
try:
async with ctx.typing():
resp = await openai.Image.acreate(prompt=prompt, size='256x256')
await ctx.reply(resp['data'][0]['url'])
except OpenAIError as e:
await ctx.reply('Hmm... Who am I? What is DimBot? Sus\n' + e.user_message)

@commands.command(brief='DALL-E 3 image generation')
@missile.cooldown_no_rainbow(1, 1200, commands.BucketType.user)
async def de3(self, ctx, *, prompt: str):
try:
async with ctx.typing():
resp = await openai.Image.acreate(prompt=prompt, model='dall-e-3')
await ctx.reply(resp['data'][0]['url'])
except OpenAIError as e:
await ctx.reply('Hmm... Who am I? What is DimBot? Sus\n' + e.user_message)

0 comments on commit b121a34

Please sign in to comment.