root 2 éve
szülő
commit
05ec706958
2 módosított fájl, 54 hozzáadás és 2 törlés
  1. 47 1
      bot/cogs/admin.py
  2. 7 1
      bot/query/channel.py

+ 47 - 1
bot/cogs/admin.py

@@ -2,12 +2,54 @@ from discord.ext import commands
 import discord
 import time
 from typing import Optional
-from query.channel import get_interact
+from query.channel import get_interact, set_interact, set_games
 from query.user import ignore_user, unignore_user, is_ignored
 from common.logging import report
 from common.settings import check_ignore
 
 
+class MyView(discord.ui.View):
+	#@discord.ui.button(label="Duplicate the current settings to all channels", row=0, style=discord.ButtonStyle.primary)
+	#async def first_button_callback(self, button, interaction):
+	#	await interaction.response.send_message("You pressed me!")
+
+	#@discord.ui.button(label="Reset all settings to default", row=0, style=discord.ButtonStyle.primary)
+	#async def second_button_callback(self, button, interaction):
+	#	await interaction.response.send_message("You pressed me!")
+
+	@discord.ui.select(
+		row=0,
+		options=[
+			discord.SelectOption(
+				label="Interact",
+				description="Have me interact in the chat."
+			),
+			discord.SelectOption(
+				label="Ignore",
+				description="Do not mingle in the chat."
+			),
+		]
+	)
+	async def first_select_callback(self, select, interaction):
+		await set_interact(self.bot.pg, select.values[0], interaction.channel.id)
+
+	@discord.ui.select(
+		row=1,
+		options=[
+			discord.SelectOption(
+				label="Games",
+				description="Activate discord games like ActiveRPG."
+			),
+			discord.SelectOption(
+				label="Serious",
+				description="No fun commands."
+			),
+		]
+	)
+	async def second_select_callback(self, select, interaction):
+		await interaction.response.send_message(f"Awesome! I like {select.values[0]} too!")
+
+
 class ChannelSettingsModal(discord.ui.Modal):
 	def __init__(self, *args, **kwargs) -> None:
 		super().__init__(*args, **kwargs)
@@ -27,6 +69,10 @@ class Admin(commands.Cog):
 	def __init__(self, bot): # Special method that is called when the cog is loaded
 		self.bot = bot
 
+	@commands.slash_command()
+	async def flavor(self, ctx):
+		await ctx.respond("Adjust channel settings.", view=MyView())
+
 	@commands.slash_command()
 	async def modal_slash(self, ctx: discord.ApplicationContext):
 		"""Shows an example of a modal dialog being invoked from a slash command."""

+ 7 - 1
bot/query/channel.py

@@ -4,5 +4,11 @@ async def insert_channel(pg, channel_id, guild_id):
 async def get_interact(pg, channel_id):
 	return await pg.fetchval("SELECT interact FROM channel WHERE channel_id=$1::bigint", channel_id)
 
+async def set_interact(pg, value, channel_id):
+	await pg.execute("UPDATE channel SET interact = $1 WHERE channel_id=$2::bigint", value, channel_id)
+
 async def get_games(pg, channel_id):
-	return await pg.fetchval("SELECT games FROM channel WHERE channel_id=$1::bigint", channel_id)
+	return await pg.fetchval("SELECT games FROM channel WHERE channel_id=$1::bigint", channel_id)
+
+async def set_games(pg, value, channel_id):
+	await pg.execute("UPDATE channel SET games = $1 WHERE channel_id=$2::bigint", value, channel_id)