move all configuration options into json file

This commit is contained in:
xenofem 2020-05-14 15:26:15 -04:00
parent ffc81bf4ce
commit 0d6ba5e8a8
3 changed files with 20 additions and 11 deletions

2
.gitignore vendored
View file

@ -1,5 +1,5 @@
token
*~
corpus.txt
markov.json
config.json
env/

9
config.json.example Normal file
View file

@ -0,0 +1,9 @@
{
"mode": "reply",
"reply_invfreq": 50,
"reply_delay_min": 10,
"reply_delay_max": 180,
"timed_interval_min": 7200,
"timed_interval_max": 14400,
"token": "tOk3N"
}

View file

@ -6,9 +6,8 @@ import json
import random
import sys
TIMED = 0
REPLY = 1
mode = REPLY
TIMED = "timed"
REPLY = "reply"
START = "__START"
END = "__END"
@ -16,6 +15,9 @@ END = "__END"
with open('markov.json') as f:
markov = json.load(f)
with open('config.json') as f:
config = json.load(f)
def gen_sentence():
cur = START
output = []
@ -31,7 +33,7 @@ class MyClient(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if mode == TIMED:
if config['mode'] == TIMED:
self.bg_task = self.loop.create_task(self.background())
async def on_ready(self):
@ -45,8 +47,8 @@ class MyClient(discord.Client):
await message.channel.send(gen_sentence())
return
if mode == REPLY and random.randrange(50) == 0:
await asyncio.sleep(random.randrange(180))
if config['mode'] == REPLY and random.randrange(config['reply_invfreq']) == 0:
await asyncio.sleep(random.randrange(config['reply_delay_min'], config['reply_delay_max']))
await message.channel.send(gen_sentence())
return
@ -59,11 +61,9 @@ class MyClient(discord.Client):
await channel.send(gen_sentence())
except:
pass
await asyncio.sleep((2700 + random.randrange(1800)) // min(max(len(self.guilds), 1), 100))
await asyncio.sleep(max(30, random.randrange(config['timed_interval_min'], config['timed_interval_max']) // max(1, len(self.guilds))))
if self.is_closed():
break
client = MyClient()
with open('token') as f:
token = f.read().strip()
client.run(token)
client.run(config['token'])