Created a config json file for the default values
This commit is contained in:
parent
aad81bbf06
commit
9e3bca1482
35
bot.py
35
bot.py
@ -1,15 +1,31 @@
|
||||
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
|
||||
count_to_prime_spam = 0
|
||||
capital_warning = {}
|
||||
capital_warning = {}
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(token=os.environ['TMI_TOKEN'],
|
||||
@ -20,6 +36,9 @@ class Bot(commands.Bot):
|
||||
self.client = Client(os.environ['TMI_TOKEN'])
|
||||
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...
|
||||
@ -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,10 +103,11 @@ 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'],
|
||||
os.environ['INSTAGRAM'],
|
||||
os.environ['DISCORD'],
|
||||
os.environ['ITCHIO']))
|
||||
await ctx.send('Twitter: {} || Instagram: {} || Instagram de mechas: {} ||'
|
||||
' Itch: {}'.format(os.environ['TWITTER'],
|
||||
os.environ['INSTAGRAM'],
|
||||
os.environ['INSTAGRAM_MECHA'],
|
||||
os.environ['ITCHIO']))
|
||||
|
||||
@commands.command(name='placaje')
|
||||
async def get_random_chatter(self, ctx):
|
||||
|
||||
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