Created a config json file for the default values
This commit is contained in:
parent
aad81bbf06
commit
9e3bca1482
29
bot.py
29
bot.py
@ -1,10 +1,26 @@
|
|||||||
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
|
||||||
@ -21,6 +37,9 @@ class Bot(commands.Bot):
|
|||||||
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...
|
||||||
print(f'Logged in as | {self.nick}')
|
print(f'Logged in as | {self.nick}')
|
||||||
@ -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,9 +103,10 @@ 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: {} ||'
|
||||||
|
' Itch: {}'.format(os.environ['TWITTER'],
|
||||||
os.environ['INSTAGRAM'],
|
os.environ['INSTAGRAM'],
|
||||||
os.environ['DISCORD'],
|
os.environ['INSTAGRAM_MECHA'],
|
||||||
os.environ['ITCHIO']))
|
os.environ['ITCHIO']))
|
||||||
|
|
||||||
@commands.command(name='placaje')
|
@commands.command(name='placaje')
|
||||||
|
|||||||
2
config.json
Normal file
2
config.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{"water_limit": 10,
|
||||||
|
"prime_spam_limit": 15}
|
||||||
Loading…
Reference in New Issue
Block a user