Browse Source

Clean up code and add an update command

master
Agatha 5 months ago
parent
commit
f9b921f122
Signed by: sorceress <agatharose@wantscuddl.es> GPG Key ID: 2DB18BA2E0A80BC3
1 changed files with 20 additions and 13 deletions
  1. +20
    -13
      main.py

+ 20
- 13
main.py View File

@@ -72,7 +72,6 @@ MEMBER_WHITELIST = [
614213232017670147,
623131255331880963,
687740609703706630,
448354605617643520,
168487634866405376,
645736256663191553,
568909777401413657,
@@ -256,20 +255,28 @@ async def populate(ctx, limit: int = 500):


@client.command()
async def generate(ctx, text_in: str = 'uwu'):
# pick a random user
filename = f'data/{random.choice(os.listdir("data/"))}'
# check if the file exists and open it
if os.path.isfile(filename):
with open(filename) as f:
# load the messages
data = json.load(f)
messages = '\n'.join(data['messages'])
async def update(ctx):
# find the server to get data from
guild = discord.utils.find(
lambda g: g.id == SOURCE_SERVER_ID, client.guilds)

# iterate over all user files
for user in os.listdir("data/"):
if re.match(r'\d+\.json', user):
# load the data as a json object
with open(f'data/{user}') as f:
data = json.load(f)

# remove `.json` from the filename
user_id = int(user[:-5])

markov = markovify.NewlineText(messages, well_formed=False)
# update their name and avatar
data['displayname'] = guild.get_member(user_id).display_name
data['avatar'] = str(guild.get_member(user_id).avatar_url)

# print output to console
print(markov.make_sentence() + '\n')
# write data
with open(f'data/{user}', 'w') as f:
json.dump(data, f)


client.run(TOKEN)

Loading…
Cancel
Save