Created a config json file for the default values

This commit is contained in:
JKuijperM 2025-06-20 13:10:46 +02:00
parent aad81bbf06
commit 9e3bca1482
2 changed files with 30 additions and 7 deletions

35
bot.py
View File

@ -1,15 +1,31 @@
import os import os
import json
from random import randrange from random import randrange
from dotenv import load_dotenv from dotenv import load_dotenv
from twitchio.ext import commands from twitchio.ext import commands
from twitchio.http import TwitchHTTP from twitchio.http import TwitchHTTP
from twitchio import PartialUser, Client from twitchio import PartialUser, Client
def load_config_file():
content = {}
with open('config.json', 'r') as f:
content = json.load(f)
if not content:
content = {'water_limit': 10,
'prime_spam_limit': 15}
save_config_file(content)
return content
def save_config_file(new_content):
with open('config.json', 'w', encoding='utf-8') as f:
json.dump(new_content, f, ident=4)
class Bot(commands.Bot): class Bot(commands.Bot):
count_to_hydrate = 0 count_to_hydrate = 0
count_to_prime_spam = 0 count_to_prime_spam = 0
capital_warning = {} capital_warning = {}
def __init__(self): def __init__(self):
super().__init__(token=os.environ['TMI_TOKEN'], super().__init__(token=os.environ['TMI_TOKEN'],
@ -20,6 +36,9 @@ class Bot(commands.Bot):
self.client = Client(os.environ['TMI_TOKEN']) self.client = Client(os.environ['TMI_TOKEN'])
self.http = TwitchHTTP(client=self.client, client_id=os.environ['CLIENT_ID'], self.http = TwitchHTTP(client=self.client, client_id=os.environ['CLIENT_ID'],
client_secret=os.environ['CLIENT_SECRET']) client_secret=os.environ['CLIENT_SECRET'])
self.default_values = load_config_file()
async def event_ready(self): async def event_ready(self):
# We are logged in and ready to chat and use commands... # We are logged in and ready to chat and use commands...
@ -44,10 +63,10 @@ class Bot(commands.Bot):
# For each 100 messages, send one # For each 100 messages, send one
self.count_to_hydrate += 1 self.count_to_hydrate += 1
self.count_to_prime_spam += 1 self.count_to_prime_spam += 1
if self.count_to_hydrate == 10: if self.count_to_hydrate == self.default_values['water_limit']:
self.count_to_hydrate = 0 self.count_to_hydrate = 0
await ctx.channel.send('/me Recordad hidrataros!!') await ctx.channel.send('/me Recordad hidrataros!!')
if self.count_to_prime_spam == 15: if self.count_to_prime_spam == self.default_values['prime_spam_limit']:
self.count_to_prime_spam = 0 self.count_to_prime_spam = 0
await ctx.channel.send( await ctx.channel.send(
'/me Recordad que si queréis apoyar el directo, podéis utilizar el prime en este canal.') '/me Recordad que si queréis apoyar el directo, podéis utilizar el prime en este canal.')
@ -75,6 +94,7 @@ class Bot(commands.Bot):
# user_id=ctx.author.id, duration=5, reason="Spam de mayúsculas") # user_id=ctx.author.id, duration=5, reason="Spam de mayúsculas")
# await ctx.author.timeout_user(token=os.environ['TMI_TOKEN'], moderator_id=os.environ['CLIENT_ID'], # await ctx.author.timeout_user(token=os.environ['TMI_TOKEN'], moderator_id=os.environ['CLIENT_ID'],
# user_id=ctx.author.id, duration=5, reason="Spam de mayúsculas") # user_id=ctx.author.id, duration=5, reason="Spam de mayúsculas")
# TODO: command to stop the bot
else: else:
self.capital_warning[ctx.author.name] = 1 self.capital_warning[ctx.author.name] = 1
await ctx.channel.send('Menos gritos con los gritos @{}. Este es el primer aviso ten ' await ctx.channel.send('Menos gritos con los gritos @{}. Este es el primer aviso ten '
@ -83,10 +103,11 @@ class Bot(commands.Bot):
@commands.command(name='redes') @commands.command(name='redes')
async def social(self, ctx): async def social(self, ctx):
print('\nSending social media...') print('\nSending social media...')
await ctx.send('Twitter: {} || Instagram: {} || Discord: {} || Itch: {}'.format(os.environ['TWITTER'], await ctx.send('Twitter: {} || Instagram: {} || Instagram de mechas: {} ||'
os.environ['INSTAGRAM'], ' Itch: {}'.format(os.environ['TWITTER'],
os.environ['DISCORD'], os.environ['INSTAGRAM'],
os.environ['ITCHIO'])) os.environ['INSTAGRAM_MECHA'],
os.environ['ITCHIO']))
@commands.command(name='placaje') @commands.command(name='placaje')
async def get_random_chatter(self, ctx): async def get_random_chatter(self, ctx):

2
config.json Normal file
View File

@ -0,0 +1,2 @@
{"water_limit": 10,
"prime_spam_limit": 15}