Compare commits
2 commits
85a4fa85ae
...
1aaf0d366b
Author | SHA1 | Date | |
---|---|---|---|
1aaf0d366b | |||
30057b2779 |
4 changed files with 40 additions and 1 deletions
|
@ -21,6 +21,7 @@ bot = commands.Bot()
|
||||||
cogs_list = [
|
cogs_list = [
|
||||||
'basic',
|
'basic',
|
||||||
'roles',
|
'roles',
|
||||||
|
'messages',
|
||||||
'ksp',
|
'ksp',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
37
hrochobot/cogs/messages.py
Normal file
37
hrochobot/cogs/messages.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
from discord.utils import get
|
||||||
|
import hrochobot.utils.data as data
|
||||||
|
|
||||||
|
MESSAGES_JSON = "messages"
|
||||||
|
|
||||||
|
def as_reply(message: str):
|
||||||
|
return "\n".join(map(lambda x: f"> {x}", message.split('\n')))
|
||||||
|
|
||||||
|
class Messages(commands.Cog):
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@discord.message_command()
|
||||||
|
async def forward(self, ctx: discord.Interaction, 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)
|
||||||
|
|
||||||
|
forward_channel = get(ctx.guild.channels, id=messages_json["forward_channel"])
|
||||||
|
header_text = f"{ctx.author.mention} forwarded:\n{message.author.mention} wrote in {message.channel.mention}:\n"
|
||||||
|
await forward_channel.send(f"{header_text}{as_reply(message.clean_content)}")
|
||||||
|
return await ctx.respond("Message successfully forwarded.", ephemeral=True)
|
||||||
|
|
||||||
|
@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):
|
||||||
|
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)
|
||||||
|
return await ctx.respond(f"Forwarding channel set to {channel.mention}.\n" + \
|
||||||
|
"Remember to set permissions for forwarding.", ephemeral=True)
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(Messages(bot))
|
|
@ -28,7 +28,7 @@ class Roles(commands.Cog):
|
||||||
data.dump_guild_data(ctx.author.guild.id, ROLES_JSON, roles)
|
data.dump_guild_data(ctx.author.guild.id, ROLES_JSON, roles)
|
||||||
return await ctx.respond(f"Secret role {role.mention} added with password {password}.", ephemeral=True)
|
return await ctx.respond(f"Secret role {role.mention} added with password {password}.", ephemeral=True)
|
||||||
|
|
||||||
@secret_roles.command(description="Lists all passwords and their secret roles")
|
@secret_roles.command(description="Lists all passwords and their secret roles.")
|
||||||
async def list(self, ctx):
|
async def list(self, ctx):
|
||||||
roles = data.load_guild_data(ctx.author.guild.id, ROLES_JSON)
|
roles = data.load_guild_data(ctx.author.guild.id, ROLES_JSON)
|
||||||
if len(roles["secret_roles"]) == 0:
|
if len(roles["secret_roles"]) == 0:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
TEMPLATES = {
|
TEMPLATES = {
|
||||||
'roles.json' : '{"secret_roles": {}}',
|
'roles.json' : '{"secret_roles": {}}',
|
||||||
|
'messages.json' : '{}',
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue