From 2ee127bce2012e6eb694c72747192fc703b4e37d Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Mon, 17 Jun 2024 20:11:44 +0100 Subject: [PATCH 1/6] Fix ytdl --- src/cogs/ytdl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cogs/ytdl.py b/src/cogs/ytdl.py index d73c673..df232cc 100644 --- a/src/cogs/ytdl.py +++ b/src/cogs/ytdl.py @@ -485,7 +485,7 @@ class YTDLCog(commands.Cog): await ctx.edit(view=None) try: if audio_only is False: - file: Path = next(temp_dir.glob("*." + extracted_info["ext"])) + file: Path = next(temp_dir.glob("*." + extracted_info.get("ext", "*"))) else: # can be .opus, .m4a, .mp3, .ogg, .oga for _file in temp_dir.iterdir(): @@ -495,7 +495,7 @@ class YTDLCog(commands.Cog): else: raise StopIteration except StopIteration: - ext = extracted_info["ext"] + ext = extracted_info.get("ext", "*") self.log.warning( "Failed to locate downloaded file. Was supposed to be looking for a file extension of " "%r amongst files %r, however none were found.", From 428f511abe679eb788021c4d87979e6d268bd6f5 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 19 Jun 2024 17:50:33 +0100 Subject: [PATCH 2/6] auto expire 0x0 referrals after 12 hours --- src/cogs/ffmeta.py | 2 +- src/cogs/ytdl.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cogs/ffmeta.py b/src/cogs/ffmeta.py index c7f2d92..ef69879 100644 --- a/src/cogs/ffmeta.py +++ b/src/cogs/ffmeta.py @@ -287,7 +287,7 @@ class FFMeta(commands.Cog): "-y", "-f", "mp4", - f"-r", + "-r", "5", "pipe:1", stdout=asyncio.subprocess.PIPE, diff --git a/src/cogs/ytdl.py b/src/cogs/ytdl.py index df232cc..bc4338e 100644 --- a/src/cogs/ytdl.py +++ b/src/cogs/ytdl.py @@ -221,6 +221,7 @@ class YTDLCog(commands.Cog): response = await client.post( "https://0x0.st", files={"file": (name, data, mime_type)}, + data={"expires": 12}, headers={"User-Agent": "CollegeBot (matrix: @nex:nexy7574.co.uk)"}, ) if response.status_code == 200: @@ -228,7 +229,6 @@ class YTDLCog(commands.Cog): response.raise_for_status() @commands.slash_command(name="yt-dl") - # @commands.bot_has_permissions(send_messages=True, embed_links=True, attach_files=True) async def yt_dl_command( self, ctx: discord.ApplicationContext, From ae968be9de7d0bd1b835cc73de5776d4a485963d Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 19 Jun 2024 17:54:02 +0100 Subject: [PATCH 3/6] refer to the gist for 0x0 admins --- src/cogs/ytdl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cogs/ytdl.py b/src/cogs/ytdl.py index bc4338e..c3023c5 100644 --- a/src/cogs/ytdl.py +++ b/src/cogs/ytdl.py @@ -222,7 +222,7 @@ class YTDLCog(commands.Cog): "https://0x0.st", files={"file": (name, data, mime_type)}, data={"expires": 12}, - headers={"User-Agent": "CollegeBot (matrix: @nex:nexy7574.co.uk)"}, + headers={"User-Agent": "CollegeBot (see: https://gist.i-am.nexus/nex/f63fcb9eb389401caf66d1dfc3c7570c)"}, ) if response.status_code == 200: return urlparse(response.text).path[1:] From 0f631e003db3d0acf4ee5056e4403358f07fa2a5 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Tue, 25 Jun 2024 23:43:49 +0100 Subject: [PATCH 4/6] Alter the penis algorithm --- src/cogs/gay_meter.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/cogs/gay_meter.py b/src/cogs/gay_meter.py index 96828f1..6c73923 100644 --- a/src/cogs/gay_meter.py +++ b/src/cogs/gay_meter.py @@ -13,6 +13,7 @@ class MeterCog(commands.Cog): self.cache = {} @commands.slash_command(name="gay-meter") + @discord.guild_only() async def gay_meter(self, ctx: discord.ApplicationContext, user: discord.User = None): """Checks how gay someone is""" user = user or ctx.user @@ -21,23 +22,34 @@ class MeterCog(commands.Cog): for i in range(0, 125, 25): await ctx.edit(content="Calculating... %d%%" % i) await asyncio.sleep(random.randint(1, 30) / 10) - - pct = user.id % 100 + + if random.randint(0, 1): + pct = sum((user.id, ctx.user.id, ctx.channel.id, ctx.guild.id)) % 400 + else: + pct = user.id % 100 await ctx.edit(content=f"{user.mention} is {pct}% gay.") @commands.slash_command(name="penis-length") async def penis_meter(self, ctx: discord.ApplicationContext, user: discord.User = None): """Checks the length of someone's penis.""" user = user or ctx.user - n = self.cache.get(user) or random.randint(0, 100) + if random.randint(0, 1): + pct = sum((user.id, ctx.user.id)) % 200 + else: + pct = user.id % 125 + pct = pct chunks = ["8"] - chunks += ["="] * n + chunks += ["="] * pct chunks.append("B") - self.cache[user] = n + inch = pct * 0.3937008 + im = "inch" + if pct > 30.48: + im = "ft" + inch = pct * 0.0328084 return await ctx.respond( embed=discord.Embed( title=f"{user.display_name}'s penis length:", - description="%d cm\n%s" % (n, "".join(chunks)) + description="%d cm (%.2f%s)\n%s" % (pct, inch, im, "".join(chunks)) ) ) From e39134719a306bcb5da08f7fbd1f697b8f05734d Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Thu, 27 Jun 2024 00:35:49 +0100 Subject: [PATCH 5/6] Allow abort failover to CPU-based instances --- config.example.toml | 1 + src/cogs/ollama.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/config.example.toml b/config.example.toml index 89e5f59..d889fab 100644 --- a/config.example.toml +++ b/config.example.toml @@ -34,6 +34,7 @@ allowed_models = [ # Note that every model has a tag called "latest" which is the most recent version. ] base_url = "http://ollama:11434/api" # this is the default if you're running via docker compose +is_gpu = false [ollama.external] owner = 421698654189912064 diff --git a/src/cogs/ollama.py b/src/cogs/ollama.py index 58f21fe..7fb5804 100644 --- a/src/cogs/ollama.py +++ b/src/cogs/ollama.py @@ -461,6 +461,28 @@ class PromptSelector(discord.ui.View): @discord.ui.button(label="Done", style=discord.ButtonStyle.success, custom_id="done") async def done(self, btn: discord.ui.Button, interaction: Interaction): + self.ctx.interaction = interaction + self.stop() + + +class ConfirmCPURun(discord.ui.View): + def __init__(self, ctx: discord.ApplicationContext): + super().__init__(timeout=600, disable_on_timeout=True) + self.ctx = ctx + self.proceed = False + + async def interaction_check(self, interaction: Interaction) -> bool: + return interaction.user == self.ctx.user + + @discord.ui.button(label="Run on CPU", style=discord.ButtonStyle.primary, custom_id="cpu") + async def run_on_cpu(self, btn: discord.ui.Button, interaction: Interaction): + await interaction.response.defer(invisible=True) + self.proceed = True + self.stop() + + @discord.ui.button(label="Abort", style=discord.ButtonStyle.primary, custom_id="gpu") + async def run_on_gpu(self, btn: discord.ui.Button, interaction: Interaction): + await interaction.response.defer(invisible=True) self.stop() @@ -637,6 +659,24 @@ class Ollama(commands.Cog): for i in range(10): try: server = self.next_server(tried) + if server and CONFIG["ollama"]["server"].get("is_gpu", False) is not True: + cf = ConfirmCPURun(ctx) + await ctx.edit( + embed=discord.Embed( + title=f"Server {server} is available, but...", + description="It is CPU only, which means it is very slow and will likely crash.\n" + "If you really want, you can continue your generation, using this " + "server. Be aware though, once in motion, it cannot be stopped.\n\n" + "" + "Continue?", + color=discord.Color.red(), + ), + view=cf + ) + await cf.wait() + await ctx.edit(view=None) + if cf.proceed: + break except RuntimeError: tried.add(server) continue From f092e4db480a9b4bffa3a9fdb544902fa0347895 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Thu, 27 Jun 2024 00:50:21 +0100 Subject: [PATCH 6/6] Add second config check --- src/cogs/ollama.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/cogs/ollama.py b/src/cogs/ollama.py index 7fb5804..5223256 100644 --- a/src/cogs/ollama.py +++ b/src/cogs/ollama.py @@ -792,6 +792,27 @@ class Ollama(commands.Cog): key = os.urandom(6).hex() + if server_config.get("is_gpu", False) is False: + cf2 = ConfirmCPURun(ctx) + await ctx.edit( + content=None, + embed=discord.Embed( + title="Before you continue", + description="You've selected a CPU-only server. This will be really slow. This will also likely" + " bring the host to a halt. Consider the pain the CPU is about to endure. " + "Are you super" + " sure you want to continue? You can run `h!ollama-status` to see what servers are" + " available.", + color=discord.Color.red(), + ), + view=cf2 + ) + await cf2.wait() + if cf2.proceed is False: + return await ctx.edit("Cancelled.", embed=None, view=None) + else: + await ctx.edit(view=None) + embed = discord.Embed( title="Generating response...", description=">>> ",