diff options
| author | salmonik <raisersoft@proton.me> | 2026-01-15 14:37:22 +0100 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-01-15 14:37:22 +0100 |
| commit | edff41f3468996dad5e66d34ac8ab1f5a238751f (patch) | |
| tree | 33a567cd202fedf010764c3e4b8cae8827851f7f /cogs | |
| parent | asyncio issues when starting (diff) | |
| download | senator-sperma-edff41f3468996dad5e66d34ac8ab1f5a238751f.tar.gz senator-sperma-edff41f3468996dad5e66d34ac8ab1f5a238751f.zip | |
minor improvements
Diffstat (limited to '')
| -rw-r--r-- | cogs/ai.py | 11 | ||||
| -rw-r--r-- | cogs/compression.py | 5 | ||||
| -rw-r--r-- | cogs/music/play.py | 12 | ||||
| -rw-r--r-- | cogs/music/play_utils.py | 7 | ||||
| -rw-r--r-- | cogs/web.py | 5 |
5 files changed, 27 insertions, 13 deletions
| @@ -6,7 +6,7 @@ import logging | |||
| 6 | import requests | 6 | import requests |
| 7 | import json | 7 | import json |
| 8 | from gtts import gTTS | 8 | from gtts import gTTS |
| 9 | from .music.play_utils import PlayUtils | 9 | from cogs.music.play_utils import PlayUtils |
| 10 | import io | 10 | import io |
| 11 | logger = logging.getLogger(__name__) | 11 | logger = logging.getLogger(__name__) |
| 12 | 12 | ||
| @@ -22,8 +22,8 @@ class AI(commands.Cog): | |||
| 22 | async def senator( | 22 | async def senator( |
| 23 | self, | 23 | self, |
| 24 | ctx: discord.ApplicationContext, | 24 | ctx: discord.ApplicationContext, |
| 25 | text=discord.Option(str, "message", required=True), | 25 | text: str = discord.Option(str, "message", required=True), |
| 26 | tts=discord.Option(bool, "face?", default=False) | 26 | tts: str = discord.Option(bool, "face?", default=False) |
| 27 | ): | 27 | ): |
| 28 | await ctx.defer() | 28 | await ctx.defer() |
| 29 | 29 | ||
| @@ -38,7 +38,10 @@ class AI(commands.Cog): | |||
| 38 | "messages": [ | 38 | "messages": [ |
| 39 | { | 39 | { |
| 40 | "role": "user", | 40 | "role": "user", |
| 41 | "content": "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. You are racist and you hate other minorities. Respond in plain text, no ** or "". If the message is in Polish, respond in Polish. Respond in 100 words. Respond accordingly to this message: " + text | 41 | "content": "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. \ |
| 42 | You are racist and you hate other minorities. Respond in plain text, no ** or "". \ | ||
| 43 | If the message is in Polish, respond in Polish. Respond in 100 words. \ | ||
| 44 | Respond accordingly to this message: " + text | ||
| 42 | } | 45 | } |
| 43 | ], | 46 | ], |
| 44 | 47 | ||
diff --git a/cogs/compression.py b/cogs/compression.py index 1905d74..79f79a0 100644 --- a/cogs/compression.py +++ b/cogs/compression.py | |||
| @@ -2,7 +2,7 @@ import mimetypes | |||
| 2 | import os | 2 | import os |
| 3 | import subprocess | 3 | import subprocess |
| 4 | from typing import List, Optional | 4 | from typing import List, Optional |
| 5 | 5 | from os import PathLike | |
| 6 | import discord | 6 | import discord |
| 7 | from discord.ext import commands | 7 | from discord.ext import commands |
| 8 | import logging | 8 | import logging |
| @@ -29,8 +29,9 @@ class Compression(commands.Cog): | |||
| 29 | 29 | ||
| 30 | async def _compress_attachment(self, attachment: discord.Attachment) -> Optional[discord.File]: | 30 | async def _compress_attachment(self, attachment: discord.Attachment) -> Optional[discord.File]: |
| 31 | """Compress a single attachment and return the compressed file""" | 31 | """Compress a single attachment and return the compressed file""" |
| 32 | file_path = PathLike[str] | ||
| 32 | try: | 33 | try: |
| 33 | file_path = os.path.join(self.temp_dir, attachment.filename) | 34 | file_path: PathLike[str] | str = os.path.join(self.temp_dir, attachment.filename) |
| 34 | output_path = os.path.join(self.temp_dir, f"better_{attachment.filename}") | 35 | output_path = os.path.join(self.temp_dir, f"better_{attachment.filename}") |
| 35 | 36 | ||
| 36 | # Save the original file | 37 | # Save the original file |
diff --git a/cogs/music/play.py b/cogs/music/play.py index 2c5b641..d77d772 100644 --- a/cogs/music/play.py +++ b/cogs/music/play.py | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import discord | 2 | import discord |
| 3 | import mutagen | 3 | import mutagen |
| 4 | from typing import List, Tuple, Optional, Callable, Awaitable, Union | 4 | from typing import List, Tuple, Callable, Awaitable |
| 5 | from os import PathLike | ||
| 5 | 6 | ||
| 6 | from . import play_utils | 7 | from cogs.music import play_utils |
| 7 | from discord.ext import commands | 8 | from discord.ext import commands |
| 8 | from discord.commands import Option, OptionChoice | 9 | from discord.commands import OptionChoice |
| 9 | import logging | 10 | import logging |
| 10 | 11 | ||
| 11 | logger = logging.getLogger(__name__) | 12 | logger = logging.getLogger(__name__) |
| @@ -16,7 +17,8 @@ class Play(commands.Cog): | |||
| 16 | self.temp_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "temp") | 17 | self.temp_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "temp") |
| 17 | self.path_mapping = {} # Maps display names to full paths | 18 | self.path_mapping = {} # Maps display names to full paths |
| 18 | 19 | ||
| 19 | async def _create_search_embed(self, candidates: List[str]) -> Tuple[discord.Embed, discord.ui.View]: | 20 | @staticmethod |
| 21 | async def _create_search_embed(candidates: List[str]) -> Tuple[discord.Embed, discord.ui.View]: | ||
| 20 | """Create an embed and view for search results.""" | 22 | """Create an embed and view for search results.""" |
| 21 | embed = discord.Embed( | 23 | embed = discord.Embed( |
| 22 | title="Wyniki wyszukiwania", | 24 | title="Wyniki wyszukiwania", |
| @@ -204,7 +206,7 @@ class Play(commands.Cog): | |||
| 204 | @discord.slash_command(name="grajcuj_plik", description="grajcuj plik") | 206 | @discord.slash_command(name="grajcuj_plik", description="grajcuj plik") |
| 205 | async def play_file(self, ctx: discord.ApplicationContext, attachment: discord.Attachment = discord.Option(discord.Attachment, "co zagrać??", required=True)): | 207 | async def play_file(self, ctx: discord.ApplicationContext, attachment: discord.Attachment = discord.Option(discord.Attachment, "co zagrać??", required=True)): |
| 206 | await ctx.defer() | 208 | await ctx.defer() |
| 207 | file_path = os.path.join(self.temp_dir, attachment.filename) | 209 | file_path: PathLike[str] | str = os.path.join(self.temp_dir, attachment.filename) |
| 208 | await attachment.save(file_path) | 210 | await attachment.save(file_path) |
| 209 | await play_utils.PlayUtils(self.bot).play(ctx, file_path) | 211 | await play_utils.PlayUtils(self.bot).play(ctx, file_path) |
| 210 | 212 | ||
diff --git a/cogs/music/play_utils.py b/cogs/music/play_utils.py index 0614157..044bd1d 100644 --- a/cogs/music/play_utils.py +++ b/cogs/music/play_utils.py | |||
| @@ -113,7 +113,9 @@ class Utils: | |||
| 113 | 113 | ||
| 114 | # Boost score based on word ratio | 114 | # Boost score based on word ratio |
| 115 | score = score * (0.7 + (0.3 * word_ratio)) | 115 | score = score * (0.7 + (0.3 * word_ratio)) |
| 116 | 116 | ||
| 117 | score = int(score) | ||
| 118 | |||
| 117 | # Ensure score is within bounds | 119 | # Ensure score is within bounds |
| 118 | return min(100, max(0, score)) | 120 | return min(100, max(0, score)) |
| 119 | 121 | ||
| @@ -410,6 +412,9 @@ class PlayUtils: | |||
| 410 | async def search_local_autocomplete(cls, query: str = None, max_results: int = 10): | 412 | async def search_local_autocomplete(cls, query: str = None, max_results: int = 10): |
| 411 | """Wrapper for autocomplete searches that returns more results and allows empty query.""" | 413 | """Wrapper for autocomplete searches that returns more results and allows empty query.""" |
| 412 | # For autocomplete, we want to show more options and allow empty queries | 414 | # For autocomplete, we want to show more options and allow empty queries |
| 415 | if not query: | ||
| 416 | return [] | ||
| 417 | |||
| 413 | return await cls.search_local(query, max_results=max_results, autocomplete=True) | 418 | return await cls.search_local(query, max_results=max_results, autocomplete=True) |
| 414 | 419 | ||
| 415 | 420 | ||
diff --git a/cogs/web.py b/cogs/web.py index 9431e84..224df82 100644 --- a/cogs/web.py +++ b/cogs/web.py | |||
| @@ -24,7 +24,8 @@ class Web(commands.Cog): | |||
| 24 | ): | 24 | ): |
| 25 | await ctx.defer(ephemeral=True) | 25 | await ctx.defer(ephemeral=True) |
| 26 | headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} | 26 | headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} |
| 27 | url = f"https://duckduckgo.com/html/?q={query}" | 27 | encoded_query = urllib.parse.quote_plus(query) |
| 28 | url = f"https://duckduckgo.com/html/?q={encoded_query}" | ||
| 28 | response = requests.get(url, headers=headers) | 29 | response = requests.get(url, headers=headers) |
| 29 | 30 | ||
| 30 | logger.info(f"Query: {query}") | 31 | logger.info(f"Query: {query}") |
| @@ -47,8 +48,10 @@ class Web(commands.Cog): | |||
| 47 | title = yt.title | 48 | title = yt.title |
| 48 | except Exception: | 49 | except Exception: |
| 49 | pass | 50 | pass |
| 51 | |||
| 50 | embed.add_field(name=f"Result {i}", value=f"[{title}]({link.get('href')})", inline=False) | 52 | embed.add_field(name=f"Result {i}", value=f"[{title}]({link.get('href')})", inline=False) |
| 51 | button = discord.ui.Button(label=f"Send Result {i}") | 53 | button = discord.ui.Button(label=f"Send Result {i}") |
| 54 | |||
| 52 | async def button_callback(interaction: discord.Interaction, link=link): | 55 | async def button_callback(interaction: discord.Interaction, link=link): |
| 53 | await interaction.response.send_message(link.get('href')) | 56 | await interaction.response.send_message(link.get('href')) |
| 54 | button.callback = button_callback | 57 | button.callback = button_callback |
