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

29
bot.py
View File

@ -1,10 +1,26 @@
import os
import json
from random import randrange
from dotenv import load_dotenv
from twitchio.ext import commands
from twitchio.http import TwitchHTTP
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):
count_to_hydrate = 0
@ -21,6 +37,9 @@ class Bot(commands.Bot):
self.http = TwitchHTTP(client=self.client, client_id=os.environ['CLIENT_ID'],
client_secret=os.environ['CLIENT_SECRET'])
self.default_values = load_config_file()
async def event_ready(self):
# We are logged in and ready to chat and use commands...
print(f'Logged in as | {self.nick}')
@ -44,10 +63,10 @@ class Bot(commands.Bot):
# For each 100 messages, send one
self.count_to_hydrate += 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
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
await ctx.channel.send(
'/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")
# 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")
# TODO: command to stop the bot
else:
self.capital_warning[ctx.author.name] = 1
await ctx.channel.send('Menos gritos con los gritos @{}. Este es el primer aviso ten '
@ -83,9 +103,10 @@ class Bot(commands.Bot):
@commands.command(name='redes')
async def social(self, ctx):
print('\nSending social media...')
await ctx.send('Twitter: {} || Instagram: {} || Discord: {} || Itch: {}'.format(os.environ['TWITTER'],
await ctx.send('Twitter: {} || Instagram: {} || Instagram de mechas: {} ||'
' Itch: {}'.format(os.environ['TWITTER'],
os.environ['INSTAGRAM'],
os.environ['DISCORD'],
os.environ['INSTAGRAM_MECHA'],
os.environ['ITCHIO']))
@commands.command(name='placaje')

2
config.json Normal file
View File

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