Compare commits

..

7 commits
mail ... master

10 changed files with 78 additions and 61 deletions

View file

@ -26,3 +26,53 @@ To run the bot simply execute ``main.py``:
```sh
./main.py
```
## Commands
### Basic
#### `/sayhello`
Prints ``Hello world!``
#### `/ping`
Shows the bot's latency.
### Messages
#### `/set_forward_channel <#channel>`
Sets channel to forward messages to.
#### `>forward`
Forwards message to set channel
### Roles
#### `/secretroles`
Manages roles locked behind a password.
Lock ``@role`` behind a password ``supersecret``:
```
/secretroles add @role supersecret
```
Delete password ``supersecret``, so role is no longer obtainable with it:
```
/secretroles delete supersecret
```
List all current passwords and their roles:
```
/secretroles list
```
### KSP
Ksp related commands
#### `/task`
Generates urls for given task.
#### `/deadlines`
Shows deadlines of currently running series.
### News
#### `/news set_channel <#channel>`
Set channel for posting news.
#### `/news post_news <id>`
Post news with given `id` to set channel.

View file

@ -18,14 +18,7 @@ CONFIG = data.load_json(os.path.join(CONFIG_FOLDER, "config"))
bot = commands.Bot()
cogs_list = [
'basic',
'roles',
'messages',
'ksp',
'news',
'mail',
]
cogs_list = CONFIG["enabled_cogs"]
for cog in cogs_list:
bot.load_extension(f'hrochobot.cogs.{cog}')

View file

@ -1,4 +1,12 @@
progress "Installing Hrochobot"
echo "Creating virtual environment"
install-pkgs python3-venv
python3 -m venv /srv/hrochobot
. /srv/hrochobot/bin/activate
echo "Installing package"
cd /build/src
pip install .

View file

@ -5,10 +5,12 @@ After=network.target
[Service]
Type=exec
ExecStartPre=mkdir -p /data/hrochobot
ExecStart=/usr/local/bin/hrochobot
ExecStart=/srv/hrochobot/bin/hrochobot
Environment=HROCHOBOT_DATA=/data/hrochobot
Environment=HROCHOBOT_ETC=/data/hrochobot
Environment=HROCHOBOT_LOG=/data/log
Restart=on-failure
RestartSec=5min
[Install]
WantedBy=multi-user.target

View file

@ -1,4 +1,4 @@
FROM docker://registry.ks.matfyz.cz/gimli/base:bullseye
FROM docker://registry.ks.matfyz.cz/gimli/base:bookworm
COPY bin /build/src/bin
COPY hrochobot /build/src/hrochobot
COPY setup.py /build/src

View file

@ -1,3 +1,10 @@
{
"token": "Paste your token here."
}
"token": "Paste your token here.",
"enabled_cogs": [
"basic",
"roles",
"messages",
"ksp",
"news"
]
}

View file

@ -1,43 +0,0 @@
import discord
from discord.ext import commands
from discord.utils import get
import hrochobot.utils.data as data
MAILS_JSON = "mails"
class Mail(commands.Cog):
def __init__(self, bot):
self.bot = bot
@discord.message_command()
async def mail(self, ctx: discord.Interaction, message: discord.Message):
mails_json = data.load_data(MAILS_JSON)
if str(ctx.author.id) not in mails_json:
return await ctx.respond(f"Mail not set.", ephemeral=True)
mail = mails_json[str(ctx.author.id)]
if message.author.nick:
header = f"{message.author.nick} ({message.author})"
else:
header = f"{message.author}"
time = message.created_at.strftime("%Y-%m-%d %H:%M:%S")
header += f" wrote on {time} in channel '{message.channel}' server '{message.guild}':"
# TODO: Send mail here
print(mail)
print(f"{header}\n{message.jump_url}\n\n{message.content}")
return await ctx.respond("Message sent to email.", ephemeral=True)
@discord.slash_command(description="Sets mail for sending emails.")
@discord.option("mail", str, description="Mail to set.")
async def set_mail(self, ctx: discord.Interaction, mail: str):
mails_json = data.load_data(MAILS_JSON)
mails_json[ctx.author.id] = mail
data.dump_data(MAILS_JSON, mails_json)
return await ctx.respond(f"Mail set to ``{mail}``.", ephemeral=True)
def setup(bot):
bot.add_cog(Mail(bot))

View file

@ -13,7 +13,7 @@ class Messages(commands.Cog):
self.bot = bot
@discord.message_command()
async def forward(self, ctx: discord.Interaction, message: discord.Message):
async def forward(self, ctx, message: discord.Message):
messages_json = data.load_guild_data(ctx.guild.id, MESSAGES_JSON)
if "forward_channel" not in messages_json:
return await ctx.respond(f"Forwarding channel not set.", ephemeral=True)
@ -26,7 +26,7 @@ class Messages(commands.Cog):
@discord.slash_command(description="Sets channel for forwarding.")
@discord.option("channel", discord.TextChannel, description="Channel for forwarding.")
@discord.default_permissions(administrator=True)
async def set_forward_channel(self, ctx: discord.Interaction, channel: discord.TextChannel):
async def set_forward_channel(self, ctx, channel: discord.TextChannel):
messages_json = data.load_guild_data(ctx.guild.id, MESSAGES_JSON)
messages_json["forward_channel"] = channel.id
data.dump_guild_data(ctx.guild.id, MESSAGES_JSON, messages_json)

View file

@ -88,7 +88,7 @@ class News(commands.Cog):
checks=[commands.has_permissions(manage_guild=True)]
)
@news.command(description="Adds a new secret role.")
@news.command(description="Sets channel for posting news.")
@discord.option("channel_id", str, description="Id of the channel for sending news.")
async def set_channel(self, ctx, channel_id: str):
try:
@ -104,13 +104,14 @@ class News(commands.Cog):
data.dump_guild_data(ctx.guild.id, NEWS_JSON, news_json)
return await ctx.respond(f"News channel set to {channel.mention}.", ephemeral=True)
@news.command(description="Synchronize news feed.")
@news.command(description="Posts news of given id to set channel.")
@discord.option("id", str, description="Id of entry to send.", autocomplete=autocomplete_news_ids)
async def post_news(self, ctx, id: int):
await ctx.defer(ephemeral=True)
err = await post_news(self.bot, ctx.guild, id)
if err:
return await ctx.respond(err, ephemeral=True)
return await ctx.respond(f"News posted.", ephemeral=True)
return await ctx.respond(f"News posted.")
def setup(bot):

View file

@ -2,5 +2,4 @@ TEMPLATES = {
'roles.json' : '{"secret_roles": {}}',
'messages.json' : '{}',
'news.json' : '{}',
'mails.json' : '{}',
}