-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.py
40 lines (28 loc) · 962 Bytes
/
generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
import requests
import time
import nltk
from markovchain import Markovchain, load_data
from secret_settings import *
Discord_Token = discord_token_secret
ChannelID = discord_channel_id
def main():
if len(sys.argv) != 3:
sys.exit("usage: python generator.py n corpus_data")
# n amount of n-grams
n = int(sys.argv[1])
corpus = load_data(sys.argv[2], n)
ngrams = list(nltk.ngrams(corpus, n))
model = Markovchain(ngrams, n)
model.update()
sentence = model.generate_text()
print(sentence)
# send text message to your friends on discord using markovchain
sendMessage(Discord_Token, ChannelID, sentence)
def sendMessage(token, channel_id, message):
url = 'https://discord.com/api/v8/channels/{}/messages'.format(channel_id)
data = {"content": message}
header = {"authorization": token}
r = requests.post(url, data=data, headers=header)
if __name__ == "__main__":
main()