Synced repo using 'sync_with_huggingface' Github Action
Browse files
app.py
CHANGED
|
@@ -52,25 +52,11 @@ intents.message_content = True
|
|
| 52 |
|
| 53 |
bot = commands.Bot(command_prefix='!', intents=intents)
|
| 54 |
|
| 55 |
-
#---------------------------------------------------------------------------------------------------------------------------------------------
|
| 56 |
-
@bot.command()
|
| 57 |
-
async def info(ctx):
|
| 58 |
-
current_directory = os.getcwd()
|
| 59 |
-
temp_directory = tempfile.gettempdir()
|
| 60 |
-
await ctx.reply(f"current_directory={current_directory}\n temp_directory={temp_directory}")
|
| 61 |
#---------------------------------------------------------------------------------------------------------------------------------------------
|
| 62 |
@bot.event
|
| 63 |
async def on_ready():
|
| 64 |
print('Logged on as', bot.user)
|
| 65 |
bot.log_channel = bot.get_channel(1100458786826747945) # 1100458786826747945 = bot-test, 1107006391547342910 = lunarbot server
|
| 66 |
-
#---------------------------------------------------------------------------------------------------------------------------------------------
|
| 67 |
-
@bot.command()
|
| 68 |
-
async def commands(ctx):
|
| 69 |
-
try:
|
| 70 |
-
if await safetychecks(ctx):
|
| 71 |
-
await ctx.reply(f"Use !deepfloydif [prompt], !jojo !spidey or !sketch. Have fun! π€π")
|
| 72 |
-
except Exception as e:
|
| 73 |
-
print(f"Error: unable to help :( {e}")
|
| 74 |
#---------------------------------------------------------------------------------------------------------------------------------------------
|
| 75 |
async def safetychecks(ctx):
|
| 76 |
failure_emoji = '<:disagree:1098628957521313892>'
|
|
@@ -90,14 +76,12 @@ async def safetychecks(ctx):
|
|
| 90 |
await ctx.message.add_reaction(failure_emoji)
|
| 91 |
return False
|
| 92 |
|
|
|
|
| 93 |
# review this, may be able to remove
|
| 94 |
#β
β
check if the command is in the allowed channel(s)
|
| 95 |
bot_test = 1100458786826747945
|
| 96 |
-
deepfloydif_channel =
|
| 97 |
-
|
| 98 |
-
sketch_channel = 1114218145343877180
|
| 99 |
-
spidey_channel = 1114218191594471514
|
| 100 |
-
falcon_channel = 1116089829147557999
|
| 101 |
|
| 102 |
channel_ids = [bot_test, deepfloydif_channel, jojo_channel, spidey_channel, sketch_channel, falcon_channel]
|
| 103 |
if ctx.channel.id not in channel_ids:
|
|
@@ -105,7 +89,8 @@ async def safetychecks(ctx):
|
|
| 105 |
thread = await ctx.message.create_thread(name=f'Channel Error')
|
| 106 |
await thread.send(f"Error: {ctx.author.mention} commands are not permitted in {ctx.channel}")
|
| 107 |
await ctx.message.add_reaction(failure_emoji)
|
| 108 |
-
return False
|
|
|
|
| 109 |
|
| 110 |
'''
|
| 111 |
#β
β
check if the user has the required role(s)
|
|
@@ -135,199 +120,8 @@ async def safetychecks(ctx):
|
|
| 135 |
print(f"Error: safetychecks failed somewhere, command will not continue, {e}")
|
| 136 |
await ctx.message.reply(f"β <@811235357663297546> SC failed somewhere β {e}") # this will always ping, as long as the bot has access to the channel
|
| 137 |
await ctx.message.add_reaction(failure_emoji)
|
| 138 |
-
#------------------------------------------------------------------------------------------------------------------------------
|
| 139 |
-
async def on_message_safetychecks(message):
|
| 140 |
-
failure_emoji = '<:disagree:1098628957521313892>'
|
| 141 |
-
try:
|
| 142 |
-
if message.author.bot:
|
| 143 |
-
print(f"The bot will ignore its own messages.")
|
| 144 |
-
return False
|
| 145 |
-
|
| 146 |
-
# check if the bot is offline
|
| 147 |
-
offline_bot_role_id = 1103676632667017266
|
| 148 |
-
bot_member = message.guild.get_member(bot.user.id)
|
| 149 |
-
if any(role.id == offline_bot_role_id for role in bot_member.roles):
|
| 150 |
-
print(f"{message.author} The bot is offline or under maintenance. (Remove the offline-bot role to bring it online)")
|
| 151 |
-
return False
|
| 152 |
-
|
| 153 |
-
#β
β
check if the user has the required role(s)
|
| 154 |
-
guild_id = 879548962464493619
|
| 155 |
-
verified_role_id = 900063512829755413 # @verified = 900063512829755413, HF = 897376942817419265, fellows = 963431900825919498
|
| 156 |
-
huggingfolks_role_id = 897376942817419265
|
| 157 |
-
fellows_role_id = 963431900825919498
|
| 158 |
-
contentcreator_role_id = 928589475968323636
|
| 159 |
-
betatester_role_id = 1113511652990668893
|
| 160 |
-
|
| 161 |
-
allowed_role_ids = [huggingfolks_role_id, fellows_role_id, contentcreator_role_id, betatester_role_id]
|
| 162 |
-
guild = bot.get_guild(guild_id)
|
| 163 |
-
user_roles = message.author.roles
|
| 164 |
-
has_allowed_role = any(role.id in allowed_role_ids for role in user_roles)
|
| 165 |
-
if not has_allowed_role:
|
| 166 |
-
print(f"{ctx.author} does not have any of the required roles to activate the on_message check")
|
| 167 |
-
return False
|
| 168 |
-
|
| 169 |
-
return True
|
| 170 |
-
|
| 171 |
-
except Exception as e:
|
| 172 |
-
print(f"Error: on_message_safetychecks failed somewhere, command will not continue {e}")
|
| 173 |
-
#------------------------------------------------------------------------------------------------------------------------------
|
| 174 |
-
|
| 175 |
-
@bot.command()
|
| 176 |
-
async def deepfloydifdemo(ctx):
|
| 177 |
-
try:
|
| 178 |
-
thread = await ctx.message.create_thread(name=f'{ctx.author} Demo Thread')
|
| 179 |
-
await thread.send(f'{ctx.author.mention} Here is a demo for the !deepfloydif command!')
|
| 180 |
-
await asyncio.sleep(0.5)
|
| 181 |
-
await thread.send(f'https://cdn.discordapp.com/attachments/932563860597121054/1113483403258499142/image.png')
|
| 182 |
-
except Exception as e:
|
| 183 |
-
print(f"Error: {e}")
|
| 184 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
| 185 |
-
#----------------------------------------------------------------------------------------------------------------------------------------------
|
| 186 |
-
@bot.command()
|
| 187 |
-
async def jojodemo(ctx):
|
| 188 |
-
try:
|
| 189 |
-
thread = await ctx.message.create_thread(name=f'JoJo Demo {ctx.author} ')
|
| 190 |
-
await thread.send(f'{ctx.author.mention} Here is a demo for the !jojo command!')
|
| 191 |
-
await asyncio.sleep(0.5)
|
| 192 |
-
await thread.send(f'https://cdn.discordapp.com/attachments/932563860597121054/1114220616199966810/image.png')
|
| 193 |
-
await thread.edit(archived=True)
|
| 194 |
-
except Exception as e:
|
| 195 |
-
print(f"Error: {e}")
|
| 196 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
| 197 |
-
await thread.edit(archived=True)
|
| 198 |
-
#----------------------------------------------------------------------------------------------------------------------------------------------
|
| 199 |
-
@bot.command()
|
| 200 |
-
async def sketchdemo(ctx):
|
| 201 |
-
try:
|
| 202 |
-
thread = await ctx.message.create_thread(name=f'Sketch Demo {ctx.author} ')
|
| 203 |
-
await thread.send(f'{ctx.author.mention} Here is a demo for the !sketch command!')
|
| 204 |
-
await asyncio.sleep(0.5)
|
| 205 |
-
await thread.send(f'https://cdn.discordapp.com/attachments/932563860597121054/1114220716498370641/image.png')
|
| 206 |
-
await thread.edit(archived=True)
|
| 207 |
-
except Exception as e:
|
| 208 |
-
print(f"Error: {e}")
|
| 209 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
| 210 |
-
await thread.edit(archived=True)
|
| 211 |
-
#----------------------------------------------------------------------------------------------------------------------------------------------
|
| 212 |
-
@bot.command()
|
| 213 |
-
async def spideydemo(ctx):
|
| 214 |
-
try:
|
| 215 |
-
thread = await ctx.message.create_thread(name=f'Spidey Demo {ctx.author} ')
|
| 216 |
-
await thread.send(f'{ctx.author.mention} Here is a demo for the !spidey command!')
|
| 217 |
-
await asyncio.sleep(0.5)
|
| 218 |
-
await thread.send(f'https://cdn.discordapp.com/attachments/932563860597121054/1114220798085959690/image.png')
|
| 219 |
-
await thread.edit(archived=True)
|
| 220 |
-
except Exception as e:
|
| 221 |
-
print(f"Error: {e}")
|
| 222 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
| 223 |
-
await thread.edit(archived=True)
|
| 224 |
-
#----------------------------------------------------------------------------------------------------------------------------------------------
|
| 225 |
-
# jojo β
|
| 226 |
-
@bot.command()
|
| 227 |
-
async def jojo(ctx):
|
| 228 |
-
# img + face β
|
| 229 |
-
# img + no face β
|
| 230 |
-
# no image β
|
| 231 |
-
# no generation β
|
| 232 |
-
# responsive? β
|
| 233 |
-
# ratelimits? β
|
| 234 |
-
# safety checks?β
|
| 235 |
-
# bot no crash β
|
| 236 |
-
try:
|
| 237 |
-
if await safetychecks(ctx): #β
|
| 238 |
-
if ctx.channel.id == 1114217739473649764:
|
| 239 |
-
await ctx.message.add_reaction('<a:loading:1114111677990981692>')
|
| 240 |
-
thread = await ctx.message.create_thread(name=f'Jojo | {ctx.author}', auto_archive_duration=60)
|
| 241 |
-
if ctx.message.attachments:
|
| 242 |
-
await thread.send(f'{ctx.author.mention} Generating images in thread, can take ~1 minute...yare yare, daze ...')
|
| 243 |
-
attachment = ctx.message.attachments[0]
|
| 244 |
-
style = 'JoJo'
|
| 245 |
-
#im = jojogan.predict(attachment.url, style)
|
| 246 |
-
im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, style)
|
| 247 |
-
#await ctx.message.reply(f'Here is the {style} version of it', file=discord.File(im))
|
| 248 |
-
await thread.send(f'{ctx.author.mention} Here is the {style} version of it', file=discord.File(im))
|
| 249 |
-
|
| 250 |
-
#testing animated
|
| 251 |
-
# <a:hugging_spin:1102656012621713488>
|
| 252 |
-
await ctx.message.add_reaction('<:agree:1098629085955113011>') # β
|
| 253 |
-
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
| 254 |
-
await thread.edit(archived=True)
|
| 255 |
-
else: # no image
|
| 256 |
-
await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image π")
|
| 257 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>') # β
|
| 258 |
-
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
| 259 |
-
await thread.edit(archived=True)
|
| 260 |
-
except Exception as e: # no generation / img + no face
|
| 261 |
-
await fullqueue(e, thread)
|
| 262 |
-
print(f"Error: {e}")
|
| 263 |
-
await thread.send(f"{ctx.author.mention} Error: {e}")
|
| 264 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>') # β
|
| 265 |
-
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
| 266 |
-
await thread.edit(archived=True)
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
#----------------------------------------------------------------------------------------------------------------------------------------------
|
| 270 |
-
# Spider-Verse β
|
| 271 |
-
@bot.command()
|
| 272 |
-
async def spidey(ctx):
|
| 273 |
-
try:
|
| 274 |
-
if await safetychecks(ctx): #β
|
| 275 |
-
if ctx.channel.id == 1114218191594471514:
|
| 276 |
-
await ctx.message.add_reaction('<a:loading:1114111677990981692>')
|
| 277 |
-
thread = await ctx.message.create_thread(name=f'Spider-verse | {ctx.author}', auto_archive_duration=60)
|
| 278 |
-
if ctx.message.attachments:
|
| 279 |
-
await thread.send(f'{ctx.author.mention} Generating images in thread, can take ~1 minute...')
|
| 280 |
-
attachment = ctx.message.attachments[0]
|
| 281 |
-
style = 'Spider-Verse'
|
| 282 |
-
im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, style)
|
| 283 |
-
await thread.send(f'{ctx.author.mention} Here is the {style} version of it', file=discord.File(im))
|
| 284 |
-
await ctx.message.add_reaction('<:agree:1098629085955113011>') # img + face
|
| 285 |
-
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
| 286 |
-
await thread.edit(archived=True)
|
| 287 |
-
else: # no image
|
| 288 |
-
await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image π")
|
| 289 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
| 290 |
-
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
| 291 |
-
await thread.edit(archived=True)
|
| 292 |
-
except Exception as e: # no generation / img + no face
|
| 293 |
-
await fullqueue(e, thread)
|
| 294 |
-
print(f"Error: {e}")
|
| 295 |
-
await thread.send(f"{ctx.author.mention} Error: {e}")
|
| 296 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
| 297 |
-
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
| 298 |
-
await thread.edit(archived=True)
|
| 299 |
-
#----------------------------------------------------------------------------------------------------------------------------------------------
|
| 300 |
-
# sketch β
|
| 301 |
-
@bot.command()
|
| 302 |
-
async def sketch(ctx):
|
| 303 |
-
try:
|
| 304 |
-
if await safetychecks(ctx): #β
|
| 305 |
-
if ctx.channel.id == 1114218145343877180:
|
| 306 |
-
await ctx.message.add_reaction('<a:loading:1114111677990981692>')
|
| 307 |
-
thread = await ctx.message.create_thread(name=f'Sketch | {ctx.author}', auto_archive_duration=60)
|
| 308 |
-
if ctx.message.attachments:
|
| 309 |
-
await thread.send(f'{ctx.author.mention} Generating images in thread, can take ~1 minute...')
|
| 310 |
-
attachment = ctx.message.attachments[0]
|
| 311 |
-
#style = 'sketch'
|
| 312 |
-
im = await asyncio.get_running_loop().run_in_executor(None, jojogan.predict, attachment.url, 'sketch')
|
| 313 |
-
await thread.send(f'{ctx.author.mention} Here is the sketch version of it', file=discord.File(im))
|
| 314 |
-
await ctx.message.add_reaction('<:agree:1098629085955113011>') # img + face
|
| 315 |
-
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
| 316 |
-
await thread.edit(archived=True)
|
| 317 |
-
else: # no image
|
| 318 |
-
await thread.send(f"{ctx.author.mention} No attachments to be found...Can't animify dat! Try sending me an image π")
|
| 319 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
| 320 |
-
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
| 321 |
-
await thread.edit(archived=True)
|
| 322 |
-
except Exception as e: # no generation / img + no face
|
| 323 |
-
await fullqueue(e, thread)
|
| 324 |
-
print(f"Error: {e}")
|
| 325 |
-
await thread.send(f"{ctx.author.mention} Error: {e}")
|
| 326 |
-
await ctx.message.add_reaction('<:disagree:1098628957521313892>')
|
| 327 |
-
await ctx.message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
| 328 |
-
await thread.edit(archived=True)
|
| 329 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
| 330 |
-
async def fullqueue(e, thread):
|
| 331 |
error_message = str(e)
|
| 332 |
if "Error: Expecting value: line 1 column 1 (char 0)" in error_message:
|
| 333 |
await thread.send("Queue is full! Please try again.")
|
|
@@ -338,8 +132,6 @@ async def fullqueue(e, thread):
|
|
| 338 |
await thread.send("Space is building! Please try again after a few minutes.")
|
| 339 |
|
| 340 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
| 341 |
-
|
| 342 |
-
|
| 343 |
# deepfloydif stage 1 generation β
|
| 344 |
def inference(prompt):
|
| 345 |
negative_prompt = ''
|
|
@@ -379,7 +171,7 @@ async def deepfloydif(ctx, *, prompt: str):
|
|
| 379 |
try:
|
| 380 |
try:
|
| 381 |
if await safetychecks(ctx): #β
|
| 382 |
-
if ctx.channel.id ==
|
| 383 |
await ctx.message.add_reaction('<a:loading:1114111677990981692>')
|
| 384 |
dfif_command_message_id = ctx.message.id # we will use this in some magic later on
|
| 385 |
thread = await ctx.message.create_thread(name=f'DeepfloydIF | {prompt}', auto_archive_duration=60) # could also just use prompt, no deepfloydif
|
|
@@ -560,7 +352,7 @@ async def on_reaction_add(reaction, user): # ctx = await bot.get_context(reac
|
|
| 560 |
if not user.bot:
|
| 561 |
thread = reaction.message.channel
|
| 562 |
threadparentid = thread.parent.id
|
| 563 |
-
if threadparentid ==
|
| 564 |
# 811235357663297546 = lunarflu
|
| 565 |
if reaction.message.attachments:
|
| 566 |
if user.id == reaction.message.mentions[0].id: # if user.id == reaction.message.mentions[0].id:
|
|
@@ -618,7 +410,7 @@ async def falcon(ctx, *, prompt: str):
|
|
| 618 |
# dict[threadid, authorid]
|
| 619 |
|
| 620 |
if not ctx.author.bot:
|
| 621 |
-
if ctx.channel.id ==
|
| 622 |
#if ctx.author.id not in falcon_users: # deprecated
|
| 623 |
if ctx.author.id not in falcon_userid_threadid_dictionary:
|
| 624 |
await ctx.message.add_reaction('<a:loading:1114111677990981692>')
|
|
@@ -653,7 +445,7 @@ async def falcon(ctx, *, prompt: str):
|
|
| 653 |
elif ctx.author.id in falcon_userid_threadid_dictionary:
|
| 654 |
# get the threadid, grab the last message in that thread, link to that message
|
| 655 |
thread_id = falcon_userid_threadid_dictionary[ctx.author.id]
|
| 656 |
-
thread_link = f"https://discord.com/channels/879548962464493619/
|
| 657 |
await ctx.reply(f"{ctx.author.mention}, you already have an existing conversation here {thread_link}! Use !falconclear in the #falcon channel to start a new one.")
|
| 658 |
#------------------------------------
|
| 659 |
# post all other generations here
|
|
@@ -688,61 +480,12 @@ async def falcon(ctx, *, prompt: str):
|
|
| 688 |
@bot.command()
|
| 689 |
async def falconclear(ctx):
|
| 690 |
if not ctx.author.bot:
|
| 691 |
-
if ctx.channel.id ==
|
| 692 |
if ctx.author.id in falcon_userid_threadid_dictionary:
|
| 693 |
if ctx.author.id in falcon_dictionary:
|
| 694 |
del falcon_userid_threadid_dictionary[ctx.author.id]
|
| 695 |
del falcon_dictionary[ctx.author.id]
|
| 696 |
await ctx.reply(f"{ctx.author.mention}'s conversation has been cleared. Feel free to start a new one!")
|
| 697 |
-
#----------------------------------------------------------------------------------------------------------------------------
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
'''
|
| 702 |
-
@bot.event
|
| 703 |
-
async def on_message(message):
|
| 704 |
-
await asyncio.sleep(5)
|
| 705 |
-
# message.author.roles
|
| 706 |
-
# bot
|
| 707 |
-
# channel?
|
| 708 |
-
try:
|
| 709 |
-
if await on_message_safetychecks(message):
|
| 710 |
-
global falcon_userid_threadid_dictionary
|
| 711 |
-
global falcon_dictionary
|
| 712 |
-
# is this our unique channel (falcon thread?)
|
| 713 |
-
if message.author.id in falcon_userid_threadid_dictionary:
|
| 714 |
-
if message.channel.id == falcon_userid_threadid_dictionary[message.author.id]:
|
| 715 |
-
await message.add_reaction('<a:loading:1114111677990981692>') # helps the bot appear responsive
|
| 716 |
-
chathistory = falcon_dictionary[message.author.id]
|
| 717 |
-
instructions = "The following is a conversation between a highly knowledgeable and intelligent AI assistant, " \
|
| 718 |
-
"called Falcon, and a human user, called User. In the following interactions, " \
|
| 719 |
-
"User and Falcon will converse in natural language, and Falcon will answer User's questions. " \
|
| 720 |
-
"Falcon was built to be respectful, polite and inclusive. " \
|
| 721 |
-
"Falcon was built by the Technology Innovation Institute in Abu Dhabi. " \
|
| 722 |
-
"Falcon will never decline to answer a question, and always attempts to give an answer that " \
|
| 723 |
-
"User would be satisfied with. It knows a lot, and always tells the truth. The conversation begins."
|
| 724 |
-
# handles the blocking task in the background so the discord bot stays responsive
|
| 725 |
-
# for added security, we could verify if message.content contains symbols used in commands; But those will fail anyways (see safetychecks)
|
| 726 |
-
job = falconclient.submit(message.content, chathistory, instructions, 0.8, 0.9, fn_index=1) # job is similar to run_in_executor (but better)
|
| 727 |
-
while job.done() == False:
|
| 728 |
-
status = job.status() # this could be used for debugging etc
|
| 729 |
-
#print(status)
|
| 730 |
-
else:
|
| 731 |
-
file_paths = job.outputs() # file_paths = ["tmp123.json", "tmp456.json," etc...]
|
| 732 |
-
full_generation = file_paths[-1] # the last filepath contains the full generated text
|
| 733 |
-
with open(full_generation, 'r') as file:
|
| 734 |
-
data = json.load(file)
|
| 735 |
-
output_text = data[-1][-1] # we only need the very last/latest string for the discord bot to output
|
| 736 |
-
falcon_dictionary[message.author.id] = full_generation # update our unique conversation
|
| 737 |
-
print(output_text)
|
| 738 |
-
await message.reply(f"{output_text}") # reply to user's prompt (whatever they typed)
|
| 739 |
-
await message.remove_reaction('<a:loading:1114111677990981692>', bot.user)
|
| 740 |
-
except Exception as e:
|
| 741 |
-
print(f"Error: {e}")
|
| 742 |
-
if message.channel.id == 1116089829147557999:
|
| 743 |
-
await message.reply(f"{e} cc <@811235357663297546> (falcon error)") # ping lunarflu if something breaks
|
| 744 |
-
await asyncio.sleep(5)
|
| 745 |
-
'''
|
| 746 |
#----------------------------------------------------------------------------------------------------------------------------
|
| 747 |
# hackerllama magic to run the bot in a Hugging Face Space
|
| 748 |
def run_bot():
|
|
|
|
| 52 |
|
| 53 |
bot = commands.Bot(command_prefix='!', intents=intents)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
#---------------------------------------------------------------------------------------------------------------------------------------------
|
| 56 |
@bot.event
|
| 57 |
async def on_ready():
|
| 58 |
print('Logged on as', bot.user)
|
| 59 |
bot.log_channel = bot.get_channel(1100458786826747945) # 1100458786826747945 = bot-test, 1107006391547342910 = lunarbot server
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
#---------------------------------------------------------------------------------------------------------------------------------------------
|
| 61 |
async def safetychecks(ctx):
|
| 62 |
failure_emoji = '<:disagree:1098628957521313892>'
|
|
|
|
| 76 |
await ctx.message.add_reaction(failure_emoji)
|
| 77 |
return False
|
| 78 |
|
| 79 |
+
'''
|
| 80 |
# review this, may be able to remove
|
| 81 |
#β
β
check if the command is in the allowed channel(s)
|
| 82 |
bot_test = 1100458786826747945
|
| 83 |
+
deepfloydif_channel = 1119313215675973714
|
| 84 |
+
falcon_channel = 1119313248056004729
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
channel_ids = [bot_test, deepfloydif_channel, jojo_channel, spidey_channel, sketch_channel, falcon_channel]
|
| 87 |
if ctx.channel.id not in channel_ids:
|
|
|
|
| 89 |
thread = await ctx.message.create_thread(name=f'Channel Error')
|
| 90 |
await thread.send(f"Error: {ctx.author.mention} commands are not permitted in {ctx.channel}")
|
| 91 |
await ctx.message.add_reaction(failure_emoji)
|
| 92 |
+
return False
|
| 93 |
+
'''
|
| 94 |
|
| 95 |
'''
|
| 96 |
#β
β
check if the user has the required role(s)
|
|
|
|
| 120 |
print(f"Error: safetychecks failed somewhere, command will not continue, {e}")
|
| 121 |
await ctx.message.reply(f"β <@811235357663297546> SC failed somewhere β {e}") # this will always ping, as long as the bot has access to the channel
|
| 122 |
await ctx.message.add_reaction(failure_emoji)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
| 124 |
+
async def fullqueue(e, thread): # can improve this using jobs from gradio
|
| 125 |
error_message = str(e)
|
| 126 |
if "Error: Expecting value: line 1 column 1 (char 0)" in error_message:
|
| 127 |
await thread.send("Queue is full! Please try again.")
|
|
|
|
| 132 |
await thread.send("Space is building! Please try again after a few minutes.")
|
| 133 |
|
| 134 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
| 135 |
# deepfloydif stage 1 generation β
|
| 136 |
def inference(prompt):
|
| 137 |
negative_prompt = ''
|
|
|
|
| 171 |
try:
|
| 172 |
try:
|
| 173 |
if await safetychecks(ctx): #β
|
| 174 |
+
if ctx.channel.id == 1119313215675973714:
|
| 175 |
await ctx.message.add_reaction('<a:loading:1114111677990981692>')
|
| 176 |
dfif_command_message_id = ctx.message.id # we will use this in some magic later on
|
| 177 |
thread = await ctx.message.create_thread(name=f'DeepfloydIF | {prompt}', auto_archive_duration=60) # could also just use prompt, no deepfloydif
|
|
|
|
| 352 |
if not user.bot:
|
| 353 |
thread = reaction.message.channel
|
| 354 |
threadparentid = thread.parent.id
|
| 355 |
+
if threadparentid == 1119313215675973714: # testing-the-bot, should be whatever the deepfloydif channel is
|
| 356 |
# 811235357663297546 = lunarflu
|
| 357 |
if reaction.message.attachments:
|
| 358 |
if user.id == reaction.message.mentions[0].id: # if user.id == reaction.message.mentions[0].id:
|
|
|
|
| 410 |
# dict[threadid, authorid]
|
| 411 |
|
| 412 |
if not ctx.author.bot:
|
| 413 |
+
if ctx.channel.id == 1119313248056004729: # initial thread creation inside #falcon
|
| 414 |
#if ctx.author.id not in falcon_users: # deprecated
|
| 415 |
if ctx.author.id not in falcon_userid_threadid_dictionary:
|
| 416 |
await ctx.message.add_reaction('<a:loading:1114111677990981692>')
|
|
|
|
| 445 |
elif ctx.author.id in falcon_userid_threadid_dictionary:
|
| 446 |
# get the threadid, grab the last message in that thread, link to that message
|
| 447 |
thread_id = falcon_userid_threadid_dictionary[ctx.author.id]
|
| 448 |
+
thread_link = f"https://discord.com/channels/879548962464493619/1119313248056004729/{thread_id}"
|
| 449 |
await ctx.reply(f"{ctx.author.mention}, you already have an existing conversation here {thread_link}! Use !falconclear in the #falcon channel to start a new one.")
|
| 450 |
#------------------------------------
|
| 451 |
# post all other generations here
|
|
|
|
| 480 |
@bot.command()
|
| 481 |
async def falconclear(ctx):
|
| 482 |
if not ctx.author.bot:
|
| 483 |
+
if ctx.channel.id == 1119313248056004729:
|
| 484 |
if ctx.author.id in falcon_userid_threadid_dictionary:
|
| 485 |
if ctx.author.id in falcon_dictionary:
|
| 486 |
del falcon_userid_threadid_dictionary[ctx.author.id]
|
| 487 |
del falcon_dictionary[ctx.author.id]
|
| 488 |
await ctx.reply(f"{ctx.author.mention}'s conversation has been cleared. Feel free to start a new one!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 489 |
#----------------------------------------------------------------------------------------------------------------------------
|
| 490 |
# hackerllama magic to run the bot in a Hugging Face Space
|
| 491 |
def run_bot():
|