Kaynağa Gözat

games toggle for chanset

root 3 yıl önce
ebeveyn
işleme
9a59260746

+ 6 - 0
bot/commands/games.py

@@ -2,6 +2,7 @@ from discord.ext import commands
 import discord
 import random
 from typing import Optional
+from query.channel import get_games
 
 def setup(bot: commands.Bot):
 	bot.add_cog(Games(bot))
@@ -19,6 +20,8 @@ class Games(commands.Cog):
 		help="Roll two dice."
 	)
 	async def dice(self, ctx: commands.Context, amount: Optional[int], sides: Optional[int]):
+		if not await get_games(self.bot.pg, ctx.channel.id):
+			return
 		if not amount:
 			amount = 2
 		if not sides:
@@ -46,6 +49,9 @@ class Games(commands.Cog):
 		name="8ball"
 	)
 	async def eightball(self, ctx: commands.Context, *, question: str = None):
+		if not await get_games(self.bot.pg, ctx.channel.id):
+			return
+
 		if not question:
 			messages = [
 				"Don't forget to ask a question...",

+ 0 - 3
bot/events/general.py

@@ -48,9 +48,6 @@ class General(commands.Cog):
 				await upsert_total_messages(self.bot.pg,message.channel.id, message.author.id)
 			except asyncpg.exceptions.ForeignKeyViolationError:
 				try:
-					print(message)
-					print(message.channel)
-					print(message.guild)
 					await insert_channel(self.bot.pg, message.channel.id, message.guild.id)
 				except asyncpg.exceptions.ForeignKeyViolationError:
 					await update_guild(self.bot.pg, message.guild)

+ 1 - 0
bot/local_settings_example.py

@@ -13,3 +13,4 @@ WEB_SCHEME = "https"
 
 DISCORD_TOKEN = ""
 COMMAND_PREFIX = "!"
+OUTPUT_CHANNEL = 

+ 4 - 1
bot/query/channel.py

@@ -2,4 +2,7 @@ async def insert_channel(pg, channel_id, guild_id):
 	await pg.execute("INSERT INTO channel(channel_id, guild) VALUES($1, $2)", 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)
+	return await pg.fetchval("SELECT interact FROM channel WHERE channel_id=$1::bigint", channel_id)
+
+async def get_games(pg, channel_id):
+	return await pg.fetchval("SELECT games FROM channel WHERE channel_id=$1::bigint", channel_id)

+ 1 - 1
bot/query/initialise_database.py

@@ -12,7 +12,7 @@ async def init_db(pg):
                 channel_id BIGINT UNIQUE NOT NULL, \
                 guild BIGINT REFERENCES guild (guild_id), \
                 interact BOOL DEFAULT FALSE, \
-                games BOOL 
+                games BOOL DEFAULT FALSE, \
             )\
         ",
         "CREATE TABLE IF NOT EXISTS \

+ 9 - 1
webgui/config/forms.py

@@ -4,7 +4,7 @@ from stats.models import Channel
 class ChannelSettingsForm(forms.ModelForm):
     class Meta:
         model = Channel
-        fields = ['interact']
+        fields = ['interact', 'games']
         #fields = '__all__'
         #exclude = ['id'] #Does not need "fields = '__all__'".
         labels = {
@@ -31,6 +31,14 @@ class ChannelSettingsForm(forms.ModelForm):
                 '_help': True,
                 #'_inline': False,
             }),
+            'games': forms.CheckboxInput(attrs={
+                '_style': 'inverted toggle',
+                '_icon': 'gamepad icon',
+                '_align': 'left',
+                # '_no_label': True,
+                '_help': True,
+                # '_inline': False,
+            }),
         }
 
 # class HostForm(ModelForm):

+ 3 - 0
webgui/stats/models.py

@@ -33,6 +33,9 @@ class Channel(models.Model):
 	interact = models.BooleanField(
 		default = False,
 	)
+	games = models.BooleanField(
+		default = False,
+	)
 
 	class Meta:
 		managed = False