Compare commits

..

No commits in common. "594654e7bf98d0eaa6d164aec736366a1172295b" and "99723e6963bbd7adcf7bb93e2ffc1ac426f3c1f7" have entirely different histories.

14 changed files with 492 additions and 982 deletions

View File

@ -1,5 +0,0 @@
*
!src*
!poetry*
!pyproject.toml
!.env

View File

@ -1,14 +0,0 @@
root = true
[*]
end_of_line = lf
trim_trailing_whitespace = true
indent_style = space
insert_final_newline = true
charset = utf-8
[*.py]
indent_size = 4
[*.{yml,yaml}]
indent_size = 2

View File

@ -1,13 +1,9 @@
FROM python:3.14-slim-trixie
WORKDIR /sox
FROM python:3.11-bookworm
RUN pip install poetry
COPY pyproject.toml poetry.lock ./
RUN poetry install --without=dev
COPY . .
CMD ["poetry", "run", "python", "-m", "src"]
RUN poetry install
ENTRYPOINT ["poetry", "run", "python", "-u", "main.py"]

23
classes/bot.py Normal file
View File

@ -0,0 +1,23 @@
from disnake.ext import commands
import disnake
import dotenv
import os
dotenv.load_dotenv()
class MyBot(commands.InteractionBot):
def __init__(self):
super().__init__(intents=disnake.Intents.all())
async def on_message(self, message: disnake.Message):
if "rewrite" in message.content.lower() and "rust" in message.content.lower() and message.guild.id == int(os.environ["FUN_GUILD"]):
await message.channel.send("never, stop asking")
async def on_ready(self):
print(f"logged in as {str(self.user)}")
async def on_member_join(self, member: disnake.Member):
if member.guild.id == int(os.environ["FUN_GUILD"]):
role = member.guild.get_role(1275732314696978473)
await member.add_roles(role)

View File

@ -1,13 +0,0 @@
services:
sox:
container_name: sox
pull_policy: build
build:
context: .
dockerfile: Dockerfile
environment:
TOKEN: ${TOKEN?Bot token not provided}
FUN_GUILD: ${FUN_GUILD?Main guild ID not provided}
WELCOME_CHANNEL: $WELCOME_CHANNEL
MEMBER_ROLE: $MEMBER_ROLE

View File

@ -1,13 +1,11 @@
from src.classes.bot import MyBot
from classes.bot import MyBot
import os
import asyncio
async def main():
bot = MyBot()
bot.load_extensions("src/plugins")
bot.load_extensions("plugins")
await bot.start(os.environ["TOKEN"])
asyncio.run(main())
asyncio.run(main())

View File

@ -1,28 +1,23 @@
from disnake.ext import plugins
import disnake
import disnake_plugins as plugins
plugin = plugins.Plugin()
@plugin.slash_command(description="ping da bot real")
async def ping(inter: disnake.CommandInteraction):
em = disnake.Embed(
title="Pong!",
description=f"Ping - {int(plugin.bot.latency * 1000)}ms\nWritten with love in Python",
)
em.set_thumbnail(plugin.bot.user.display_avatar.url)
em = disnake.Embed(title="Pong!", description=f"Ping - {int(plugin.bot.latency * 1000)}ms\nWritten with love in Python")
em.set_thumbnail(plugin.bot.user.avatar.url)
await inter.response.send_message(embed=em)
@plugin.slash_command(description="help me!", name="help")
async def help_command(inter: disnake.CommandInteraction):
desc = ""
for cmd in plugin.bot.global_application_commands:
desc += f"**{cmd.name}** - {cmd.description}\n\n"
em = disnake.Embed(title="Commands", description=desc)
em.set_thumbnail(plugin.bot.user.display_avatar.url)
if plugin.bot.user.avatar:
em.set_thumbnail(plugin.bot.user.avatar.url)
await inter.response.send_message(embed=em)
setup, teardown = plugin.create_extension_handlers()
setup, teardown = plugin.create_extension_handlers()

17
plugins/fun.py Normal file
View File

@ -0,0 +1,17 @@
from disnake.ext import plugins
import disnake
import aiohttp
plugin = plugins.Plugin()
@plugin.slash_command(description="tells a (maybe) funny joke")
async def joke(inter: disnake.CommandInteraction):
async with aiohttp.ClientSession() as cs:
async with cs.get("https://v2.jokeapi.dev/joke/Programming,Miscellaneous?blacklistFlags=nsfw,political&type=single") as resp:
resp = await resp.json()
em = disnake.Embed(title="A joke for you!", description=resp["joke"], color=disnake.Color.random())
em.set_footer(text="powered by v2.jokeapi.dev")
await inter.response.send_message(embed=em)
setup, teardown = plugin.create_extension_handlers()

View File

@ -1,36 +1,37 @@
from disnake.ext import plugins
import disnake
import disnake_plugins as plugins
import soteria
plugin = plugins.Plugin()
sot = soteria.Client(cache=soteria.MemoryCache())
@plugin.unload_hook()
async def close_sot():
await sot.close()
@plugin.slash_command(description="gets the 5 most recent BANGERS (posts) from Soteria")
async def get_posts(inter: disnake.CommandInteraction):
await inter.response.defer()
r = await sot.request("GET", "/posts/all", params={"limit": 5})
r = await sot.request('GET', '/posts/all', params={"limit": 5})
embed_list = []
for post in r:
user = await soteria.User.fetch(sot, post["author"])
embed = disnake.Embed(description=post["content"], color=disnake.Color.blue())
embed = disnake.Embed(
description=post["content"],
color=disnake.Color.blue()
)
embed.set_author(
name=user.display_name if user.display_name else user.username,
url=f"https://soteria.social/{user.id}",
icon_url=soteria.Asset(client=sot, asset_id=user.avatar).url,
icon_url=soteria.Asset(client = sot, asset_id = user.avatar).url
)
embed_list.append(embed)
await inter.edit_original_response(embeds=embed_list)
setup, teardown = plugin.create_extension_handlers()
setup, teardown = plugin.create_extension_handlers()

1175
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -8,15 +8,13 @@ readme = "README.md"
package-mode = false
[tool.poetry.dependencies]
python = ">3.12,<4.0"
disnake = "^2.11.0"
python = ">3.9,<4.0"
disnake = "^2.9.2"
ruff = "^0.5.6"
disnake-ext-plugins = {git = "https://github.com/DisnakeCommunity/disnake-ext-plugins"}
python-dotenv = "^1.2.1"
python-dotenv = "^1.0.1"
pyteria = "^0.1.0"
[tool.poetry.group.dev.dependencies]
ruff = "^0.15.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

View File

@ -1,44 +0,0 @@
import os
import disnake
import dotenv
from disnake.ext import commands
dotenv.load_dotenv()
class MyBot(commands.InteractionBot):
def __init__(self) -> None:
super().__init__(
intents=disnake.Intents(
messages=True,
members=True,
guilds=True,
)
)
self.cached_guild: disnake.Guild
self.guild_member_role: disnake.Role | None = None
self.guild_welcome_channel: disnake.TextChannel | None = None
async def on_message(self, message: disnake.Message) -> None:
assert message.guild is not None
if (
"rewrite" in message.content.lower()
and "rust" in message.content.lower()
and message.guild.id == self.cached_guild.id
):
await message.channel.send("never, stop asking")
async def on_ready(self) -> None:
self.cached_guild = await self.fetch_guild(int(os.environ["FUN_GUILD"]))
if env_welcome_role := os.getenv("MEMBER_ROLE"):
self.guild_member_role = await self.cached_guild.fetch_role(
int(env_welcome_role)
)
if env_welcome_channel := os.getenv("WELCOME_CHANNEL"):
self.guild_welcome_channel = await self.cached_guild.fetch_channel( # pyright: ignore[reportAttributeAccessIssue]
int(env_welcome_channel)
)
print(f"logged in as {str(self.user)}")

View File

@ -1,24 +0,0 @@
import aiohttp
import disnake
import disnake_plugins as plugins
plugin = plugins.Plugin()
@plugin.slash_command(description="tells a (maybe) funny joke")
async def joke(inter: disnake.CommandInteraction):
async with aiohttp.ClientSession() as cs:
async with cs.get(
"https://v2.jokeapi.dev/joke/Programming,Miscellaneous?blacklistFlags=nsfw,political&type=single"
) as resp:
resp = await resp.json()
em = disnake.Embed(
title="A joke for you!",
description=resp["joke"],
color=disnake.Color.random(),
)
em.set_footer(text="powered by v2.jokeapi.dev")
await inter.response.send_message(embed=em)
setup, teardown = plugin.create_extension_handlers()

View File

@ -1,93 +0,0 @@
from datetime import UTC, datetime, timedelta
import disnake_plugins as plugins
from disnake import Event, HTTPException, Member, Message
from disnake.ext import tasks
from disnake.utils import format_dt
from src.classes.bot import MyBot
plugin = plugins.Plugin[MyBot]()
MIN_JOIN_MINUTES = 15
MIN_JOIN_DAYS = 14
last_message_store: dict[int, int] = {}
@plugin.listener(Event.member_join)
async def member_join_store(member: Member) -> None:
if not plugin.bot.guild_welcome_channel:
return
welcome_message = await plugin.bot.guild_welcome_channel.send(
f"{member.mention}, welcome to soteria! do you want music??"
)
last_message_store[member.id] = welcome_message.id
@plugin.listener(Event.message)
async def last_sent_message_store(message: Message) -> None:
last_message_store[message.author.id] = message.id
new_member_store: dict[Member, datetime] = {}
@plugin.listener(Event.member_join)
async def new_member_role_assign(member: Member) -> None:
if not member.joined_at:
return
new_member_store[member] = member.joined_at
@plugin.listener(Event.member_remove)
async def member_leave_react(member: Member) -> None:
cached_last_sent_message = last_message_store.get(member.id)
if not cached_last_sent_message:
return
last_sent_message = plugin.bot.get_message(cached_last_sent_message)
if not last_sent_message:
return
try:
await last_sent_message.add_reaction("<a:goodbye:1268952442821935289>")
except HTTPException:
await last_sent_message.add_reaction("\U0001f6aa") # door emoji
last_message_store.pop(last_message_store[member.id], None)
new_member_store.pop(member, None)
@plugin.register_loop(wait_until_ready=True)
@tasks.loop(minutes=1)
async def new_member_role_assign_timer() -> None:
if not plugin.bot.guild_member_role:
return
for member, joined_at in new_member_store.copy().items():
if datetime.now(UTC) > joined_at + timedelta(minutes=MIN_JOIN_MINUTES):
await member.add_roles(
plugin.bot.guild_member_role,
reason="member has been in the guild for 15 minutes",
)
new_member_store.pop(member, None)
@plugin.listener(Event.member_join)
async def member_created_at_checker(member: Member) -> None:
since_creation = datetime.now(tz=UTC) - member.created_at
days_since_creation = since_creation.days
if days_since_creation < MIN_JOIN_DAYS:
await member.send(
f"you have been kicked from **{member.guild.name}** as your account is not at least {MIN_JOIN_DAYS} days old. "
f"to minimise the potential for raids or spam, we will not let you join until {format_dt(member.created_at + timedelta(days=MIN_JOIN_DAYS))}."
)
await member.kick(
reason=f"account too young. only {days_since_creation} days old"
)
setup, teardown = plugin.create_extension_handlers()