Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/edenartlab/bots
Browse files Browse the repository at this point in the history
  • Loading branch information
jmilldotdev committed Mar 14, 2024
2 parents 6c67d89 + caea392 commit 3e852d9
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 58 deletions.
14 changes: 14 additions & 0 deletions src/bots/biennale/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DISCORD_TOKEN=
MONGO_URI=
MONGO_DB_NAME=

EDEN_API_URL=
EDEN_API_KEY=
EDEN_API_SECRET=
EDEN_CHARACTER_ID=

ALLOWED_GUILDS=
ALLOWED_GUILDS_TEST=
ALLOWED_CHANNELS=

LOGOS_URL=
11 changes: 11 additions & 0 deletions src/bots/biennale/EdenGeneratorCog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from discord.ext import commands
from cogs.CharacterGeneratorCog import CharacterGeneratorCog


class EdenCharacterGeneratorCog(CharacterGeneratorCog):
def __init__(self, bot: commands.bot) -> None:
super().__init__(bot)


def setup(bot: commands.Bot) -> None:
bot.add_cog(EdenCharacterGeneratorCog(bot))
11 changes: 11 additions & 0 deletions src/bots/biennale/EdenLogosCharacterCog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from discord.ext import commands
from cogs.LogosCharacterCog import LogosCharacterCog


class EdenLogosCharacterCog(LogosCharacterCog):
def __init__(self, bot: commands.bot) -> None:
super().__init__(bot)


def setup(bot: commands.Bot) -> None:
bot.add_cog(EdenLogosCharacterCog(bot))
11 changes: 9 additions & 2 deletions src/bots/eden/EdenGeneratorCog.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import asyncio
from discord.ext import commands
from cogs.CharacterGeneratorCog import CharacterGeneratorCog


class EdenCharacterGeneratorCog(CharacterGeneratorCog):
def __init__(self, bot: commands.bot) -> None:
super().__init__(bot)
# self.bot.loop.create_task(self.run_in_background())

# async def run_in_background(self):
# await self.bot.wait_until_ready()
# channel = self.bot.get_channel(1006143747588898849)
# while not self.bot.is_closed():
# await channel.send("Hello, world!")
# await asyncio.sleep(5) # wait for 5 seconds before sending the next message

def setup(bot: commands.Bot) -> None:
bot.add_cog(EdenCharacterGeneratorCog(bot))
bot.add_cog(EdenCharacterGeneratorCog(bot))
26 changes: 26 additions & 0 deletions src/bots/kojii/EdenLogosCharacterCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,36 @@
from cogs.LogosCharacterCog import LogosCharacterCog


GUILD_ID = 1128729869535150260

welcome_message = """🎨 Welcome to kojii.ai Discord! 🤖✨
Hello **{name}** and welcome to our creative space! 🚀 I'm excited to have you here as part of our community of art enthusiasts and tech explorers.
🌟 Dive into our various channels. Introduce yourself in https://discord.com/channels/1128729869535150260/1203819263731834961 and head over to https://discord.com/channels/1128729869535150260/1203819229066043433 for a relaxed conversation.
💬 Our team is here to help! If you have any questions, ideas, or need assistance, feel free to reach out to us in https://discord.com/channels/1128729869535150260/1203819834836656128.
🎙️ This Discord is a hub for creativity! Share your thoughts, ideas, or even your latest artworks in https://discord.com/channels/1128729869535150260/1203819881481506876.
🤖 Ready to unleash your creativity? Head over to your favorite artist channel and play with the models. Don't forget to share your masterpieces with the community!
🌈 Enjoy Your Stay:
We hope you have an incredible time exploring, creating, and connecting. Thank you for joining!
"""


class EdenLogosCharacterCog(LogosCharacterCog):
def __init__(self, bot: commands.bot) -> None:
super().__init__(bot)

@commands.Cog.listener()
async def on_member_join(self, member):
if member.guild.id != GUILD_ID:
return
print(f"{member} has joined the guild id: {member.guild.id}")
await member.send(welcome_message.format(name=member.name))


def setup(bot: commands.Bot) -> None:
bot.add_cog(EdenLogosCharacterCog(bot))
8 changes: 4 additions & 4 deletions src/cogs/AssistantCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
EdenAssistantConfig,
GenerationLoopInput,
SignInCredentials,
StableDiffusionConfig,
EdenConfig,
)

ALLOWED_CHANNELS = [int(c) for c in os.getenv("ALLOWED_CHANNELS", "").split(",")]
Expand Down Expand Up @@ -122,13 +122,13 @@ async def on_message(self, message: discord.Message) -> None:
if not config.get("seed"):
config["seed"] = random.randint(1, 1e8)

config = StableDiffusionConfig(generator_name=mode, **config)
config = EdenConfig(generator_name=mode, **config)

config = self.add_lora(config)

source = get_source(ctx)

is_video_request = mode in ["interpolate", "real2real"]
is_video_request = mode in ["interpolate", "real2real", "monologue", "dialogue", "story"]

start_bot_message = f"**{text_input}** - <@!{ctx.author.id}>\n"
original_text = (
Expand Down Expand Up @@ -158,7 +158,7 @@ def message_preprocessor(self, message: discord.Message) -> str:
message_content = message_content.strip()
return message_content

def add_lora(self, config: StableDiffusionConfig):
def add_lora(self, config: EdenConfig):
if self.lora:
config.lora = self.lora.lora_id
config.lora_strength = self.lora.lora_strength
Expand Down
8 changes: 4 additions & 4 deletions src/cogs/CharacterCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from common.models import (
GenerationLoopInput,
SignInCredentials,
StableDiffusionConfig,
EdenConfig,
)

ALLOWED_CHANNELS = [int(c) for c in os.getenv("ALLOWED_CHANNELS", "").split(",")]
Expand Down Expand Up @@ -117,13 +117,13 @@ async def on_message(self, message: discord.Message) -> None:
if not config.get("seed"):
config["seed"] = random.randint(1, 1e8)

config = StableDiffusionConfig(generator_name=mode, **config)
config = EdenConfig(generator_name=mode, **config)

config = self.add_lora(config, concept)

source = get_source(ctx)

is_video_request = mode in ["interpolate", "real2real"]
is_video_request = mode in ["interpolate", "real2real", "monologue", "dialogue", "story"]

start_bot_message = f"**{text_input}** - <@!{ctx.author.id}>\n"
original_text = (
Expand Down Expand Up @@ -153,7 +153,7 @@ def message_preprocessor(self, message: discord.Message) -> str:
message_content = message_content.strip()
return message_content

def add_lora(self, config: StableDiffusionConfig, concept: str):
def add_lora(self, config: EdenConfig, concept: str):
if concept:
config.lora = concept
config.lora_strength = 0.6
Expand Down
14 changes: 7 additions & 7 deletions src/cogs/CharacterGeneratorCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from common.models import (
GenerationLoopInput,
SignInCredentials,
StableDiffusionConfig,
EdenConfig,
)

ALLOWED_GUILDS = [g for g in os.getenv("ALLOWED_GUILDS", "").split(",")] or []
Expand Down Expand Up @@ -54,7 +54,7 @@ async def test(
):
print("Received test")

config = StableDiffusionConfig(
config = EdenConfig(
generator_name="test",
)

Expand Down Expand Up @@ -112,7 +112,7 @@ async def create(
width, height, upscale_f = self.get_dimensions(aspect_ratio, large)
steps = 15 if fast else 35

config = StableDiffusionConfig(
config = EdenConfig(
generator_name="create",
text_input=text_input,
width=width,
Expand Down Expand Up @@ -166,7 +166,7 @@ async def remix(
steps = 50
width, height = 1024, 1024

config = StableDiffusionConfig(
config = EdenConfig(
generator_name="remix",
text_input="remix",
init_image_data=image1.url,
Expand Down Expand Up @@ -228,7 +228,7 @@ async def real2real(
steps = 40
width, height = 768, 768

config = StableDiffusionConfig(
config = EdenConfig(
generator_name="real2real",
stream=True,
stream_every=1,
Expand Down Expand Up @@ -308,7 +308,7 @@ async def lerp(
steps = 40
width, height, upscale_f = self.get_video_dimensions(aspect_ratio, False)

config = StableDiffusionConfig(
config = EdenConfig(
generator_name="interpolate",
stream=True,
stream_every=1,
Expand Down Expand Up @@ -374,7 +374,7 @@ def perm_check(self, ctx):
return False
return True

def add_lora(self, config: StableDiffusionConfig):
def add_lora(self, config: EdenConfig):
_, concept = get_assistant(
api_url=EDEN_API_URL,
character_id=self.characterId,
Expand Down
14 changes: 7 additions & 7 deletions src/cogs/GeneratorCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from common.models import (
GenerationLoopInput,
SignInCredentials,
StableDiffusionConfig,
EdenConfig,
)

ALLOWED_GUILDS = [g for g in os.getenv("ALLOWED_GUILDS", "").split(",")] or []
Expand Down Expand Up @@ -53,7 +53,7 @@ async def test(
):
print("Received test")

config = StableDiffusionConfig(
config = EdenConfig(
generator_name="test",
)

Expand Down Expand Up @@ -111,7 +111,7 @@ async def create(
width, height, upscale_f = self.get_dimensions(aspect_ratio, large)
steps = 15 if fast else 35

config = StableDiffusionConfig(
config = EdenConfig(
generator_name="create",
text_input=text_input,
width=width,
Expand Down Expand Up @@ -165,7 +165,7 @@ async def remix(
steps = 50
width, height = 1024, 1024

config = StableDiffusionConfig(
config = EdenConfig(
generator_name="remix",
text_input="remix",
init_image_data=image1.url,
Expand Down Expand Up @@ -227,7 +227,7 @@ async def real2real(
steps = 40
width, height = 768, 768

config = StableDiffusionConfig(
config = EdenConfig(
generator_name="real2real",
stream=True,
stream_every=1,
Expand Down Expand Up @@ -307,7 +307,7 @@ async def lerp(
steps = 40
width, height, upscale_f = self.get_video_dimensions(aspect_ratio, False)

config = StableDiffusionConfig(
config = EdenConfig(
generator_name="interpolate",
stream=True,
stream_every=1,
Expand Down Expand Up @@ -373,7 +373,7 @@ def perm_check(self, ctx):
return False
return True

def add_lora(self, config: StableDiffusionConfig):
def add_lora(self, config: EdenConfig):
if self.lora:
config.lora = self.lora.lora_id
config.lora_strength = self.lora.lora_strength
Expand Down
35 changes: 25 additions & 10 deletions src/cogs/LogosCharacterCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from common.models import (
GenerationLoopInput,
SignInCredentials,
StableDiffusionConfig,
EdenConfig,
)

ALLOWED_CHANNELS = [int(c) for c in os.getenv("ALLOWED_CHANNELS", "").split(",")]
Expand Down Expand Up @@ -57,6 +57,16 @@ def __init__(

@commands.Cog.listener("on_message")
async def on_message(self, message: discord.Message) -> None:
print("thios is a message")
print("--->")
try:
print("on msg")
print(message)
print(message.content)

except Exception as e:
print(e)

if (
message.channel.id not in ALLOWED_CHANNELS
or message.author.id == self.bot.user.id
Expand All @@ -71,15 +81,15 @@ async def on_message(self, message: discord.Message) -> None:
cutoff = message.created_at - timedelta(minutes=90)
conversation_history = await message.channel.history(after=cutoff).flatten()
conversation = ""
for message in conversation_history[-10:]:
timestamp = message.created_at.strftime("%I:%M %p")
author = message.author.name
for msg in conversation_history[-10:]:
timestamp = msg.created_at.strftime("%I:%M %p")
author = msg.author.name
content = replace_mentions_with_usernames(
message.content,
message.mentions,
msg.content,
msg.mentions,
)
conversation += f"\n{author}{timestamp}\n{content}\n"
#if message.attachments:
#if msg.attachments:

request = {
"character_id": self.characterId,
Expand All @@ -93,6 +103,8 @@ async def on_message(self, message: discord.Message) -> None:
if not trigger_reply:
trigger_reply = logos_think(LOGOS_URL, request)

print("TRIG REPLY", trigger_reply)

if trigger_reply:
ctx = await self.bot.get_context(message)
async with ctx.channel.typing():
Expand All @@ -111,7 +123,10 @@ async def on_message(self, message: discord.Message) -> None:
if not config:
return

mode = config.pop("generator")
if config.get("generator"):
mode = config.pop("generator")
else:
return

if config.get("text_input"):
text_input = config["text_input"]
Expand All @@ -123,11 +138,11 @@ async def on_message(self, message: discord.Message) -> None:
if not config.get("seed"):
config["seed"] = random.randint(1, 1e8)

config = StableDiffusionConfig(generator_name=mode, **config)
config = EdenConfig(generator_name=mode, **config)

source = get_source(ctx)

is_video_request = mode in ["interpolate", "real2real"]
is_video_request = mode in ["interpolate", "real2real", "monologue", "dialogue", "story"]

start_bot_message = f"**{text_input}** - <@!{ctx.author.id}>\n"
original_text = (
Expand Down
4 changes: 4 additions & 0 deletions src/common/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def is_mentioned(message: discord.Message, user: discord.User) -> bool:
:param user: The user to check.
:return: True if the user is mentioned, False otherwise.
"""
print("--======")
print(message)
print(message.content)
print("mentions", [m.id for m in message.mentions], "---", user.id)
return user.id in [m.id for m in message.mentions]


Expand Down
Loading

0 comments on commit 3e852d9

Please sign in to comment.