Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
| 0792772c2a |
10 changed files with 61 additions and 78 deletions
50
README.md
50
README.md
|
|
@ -26,53 +26,3 @@ To run the bot simply execute ``main.py``:
|
||||||
```sh
|
```sh
|
||||||
./main.py
|
./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.
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,14 @@ CONFIG = data.load_json(os.path.join(CONFIG_FOLDER, "config"))
|
||||||
|
|
||||||
bot = commands.Bot()
|
bot = commands.Bot()
|
||||||
|
|
||||||
cogs_list = CONFIG["enabled_cogs"]
|
cogs_list = [
|
||||||
|
'basic',
|
||||||
|
'roles',
|
||||||
|
'messages',
|
||||||
|
'ksp',
|
||||||
|
'news',
|
||||||
|
'mail',
|
||||||
|
]
|
||||||
|
|
||||||
for cog in cogs_list:
|
for cog in cogs_list:
|
||||||
bot.load_extension(f'hrochobot.cogs.{cog}')
|
bot.load_extension(f'hrochobot.cogs.{cog}')
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,4 @@
|
||||||
progress "Installing Hrochobot"
|
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
|
cd /build/src
|
||||||
pip install .
|
pip install .
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,10 @@ After=network.target
|
||||||
[Service]
|
[Service]
|
||||||
Type=exec
|
Type=exec
|
||||||
ExecStartPre=mkdir -p /data/hrochobot
|
ExecStartPre=mkdir -p /data/hrochobot
|
||||||
ExecStart=/srv/hrochobot/bin/hrochobot
|
ExecStart=/usr/local/bin/hrochobot
|
||||||
Environment=HROCHOBOT_DATA=/data/hrochobot
|
Environment=HROCHOBOT_DATA=/data/hrochobot
|
||||||
Environment=HROCHOBOT_ETC=/data/hrochobot
|
Environment=HROCHOBOT_ETC=/data/hrochobot
|
||||||
Environment=HROCHOBOT_LOG=/data/log
|
Environment=HROCHOBOT_LOG=/data/log
|
||||||
Restart=on-failure
|
|
||||||
RestartSec=5min
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
FROM docker://registry.ks.matfyz.cz/gimli/base:bookworm
|
FROM docker://registry.ks.matfyz.cz/gimli/base:bullseye
|
||||||
COPY bin /build/src/bin
|
COPY bin /build/src/bin
|
||||||
COPY hrochobot /build/src/hrochobot
|
COPY hrochobot /build/src/hrochobot
|
||||||
COPY setup.py /build/src
|
COPY setup.py /build/src
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,3 @@
|
||||||
{
|
{
|
||||||
"token": "Paste your token here.",
|
"token": "Paste your token here."
|
||||||
"enabled_cogs": [
|
}
|
||||||
"basic",
|
|
||||||
"roles",
|
|
||||||
"messages",
|
|
||||||
"ksp",
|
|
||||||
"news"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
43
hrochobot/cogs/mail.py
Normal file
43
hrochobot/cogs/mail.py
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
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))
|
||||||
|
|
@ -13,7 +13,7 @@ class Messages(commands.Cog):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@discord.message_command()
|
@discord.message_command()
|
||||||
async def forward(self, ctx, message: discord.Message):
|
async def forward(self, ctx: discord.Interaction, message: discord.Message):
|
||||||
messages_json = data.load_guild_data(ctx.guild.id, MESSAGES_JSON)
|
messages_json = data.load_guild_data(ctx.guild.id, MESSAGES_JSON)
|
||||||
if "forward_channel" not in messages_json:
|
if "forward_channel" not in messages_json:
|
||||||
return await ctx.respond(f"Forwarding channel not set.", ephemeral=True)
|
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.slash_command(description="Sets channel for forwarding.")
|
||||||
@discord.option("channel", discord.TextChannel, description="Channel for forwarding.")
|
@discord.option("channel", discord.TextChannel, description="Channel for forwarding.")
|
||||||
@discord.default_permissions(administrator=True)
|
@discord.default_permissions(administrator=True)
|
||||||
async def set_forward_channel(self, ctx, channel: discord.TextChannel):
|
async def set_forward_channel(self, ctx: discord.Interaction, channel: discord.TextChannel):
|
||||||
messages_json = data.load_guild_data(ctx.guild.id, MESSAGES_JSON)
|
messages_json = data.load_guild_data(ctx.guild.id, MESSAGES_JSON)
|
||||||
messages_json["forward_channel"] = channel.id
|
messages_json["forward_channel"] = channel.id
|
||||||
data.dump_guild_data(ctx.guild.id, MESSAGES_JSON, messages_json)
|
data.dump_guild_data(ctx.guild.id, MESSAGES_JSON, messages_json)
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ class News(commands.Cog):
|
||||||
checks=[commands.has_permissions(manage_guild=True)]
|
checks=[commands.has_permissions(manage_guild=True)]
|
||||||
)
|
)
|
||||||
|
|
||||||
@news.command(description="Sets channel for posting news.")
|
@news.command(description="Adds a new secret role.")
|
||||||
@discord.option("channel_id", str, description="Id of the channel for sending news.")
|
@discord.option("channel_id", str, description="Id of the channel for sending news.")
|
||||||
async def set_channel(self, ctx, channel_id: str):
|
async def set_channel(self, ctx, channel_id: str):
|
||||||
try:
|
try:
|
||||||
|
|
@ -104,14 +104,13 @@ class News(commands.Cog):
|
||||||
data.dump_guild_data(ctx.guild.id, NEWS_JSON, news_json)
|
data.dump_guild_data(ctx.guild.id, NEWS_JSON, news_json)
|
||||||
return await ctx.respond(f"News channel set to {channel.mention}.", ephemeral=True)
|
return await ctx.respond(f"News channel set to {channel.mention}.", ephemeral=True)
|
||||||
|
|
||||||
@news.command(description="Posts news of given id to set channel.")
|
@news.command(description="Synchronize news feed.")
|
||||||
@discord.option("id", str, description="Id of entry to send.", autocomplete=autocomplete_news_ids)
|
@discord.option("id", str, description="Id of entry to send.", autocomplete=autocomplete_news_ids)
|
||||||
async def post_news(self, ctx, id: int):
|
async def post_news(self, ctx, id: int):
|
||||||
await ctx.defer(ephemeral=True)
|
|
||||||
err = await post_news(self.bot, ctx.guild, id)
|
err = await post_news(self.bot, ctx.guild, id)
|
||||||
if err:
|
if err:
|
||||||
return await ctx.respond(err, ephemeral=True)
|
return await ctx.respond(err, ephemeral=True)
|
||||||
return await ctx.respond(f"News posted.")
|
return await ctx.respond(f"News posted.", ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,5 @@ TEMPLATES = {
|
||||||
'roles.json' : '{"secret_roles": {}}',
|
'roles.json' : '{"secret_roles": {}}',
|
||||||
'messages.json' : '{}',
|
'messages.json' : '{}',
|
||||||
'news.json' : '{}',
|
'news.json' : '{}',
|
||||||
|
'mails.json' : '{}',
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue