Browse Source

add rudimentary irc bot script

master
XJulep 4 years ago
parent
commit
a3577c926b
  1. 2
      .gitignore
  2. 7
      config.py
  3. 28
      irc.py
  4. 30
      markov.py

2
.gitignore

@ -0,0 +1,2 @@
*.txt
__pycache__/

7
config.py

@ -0,0 +1,7 @@
server = "irc.???.net"
port = 6667
nick = ""
mode = ""
realname = ""
nicks = ['','','']
room = ""

28
irc.py

@ -0,0 +1,28 @@
#!/usr/bin/env python3
import socket
import markov
import time
import config
s = socket.socket()
s.connect((config.server, config.port))
s.send(bytes("NICK %s\n" % config.nick, "UTF-8"))
s.send(bytes("USER %s %s unused :%s\n\n" % (config.mode, config.server, config.realname), "UTF-8"))
s.send(bytes("JOIN %s\n" % config.room, "UTF-8"))
while True:
srvmsg = '' + s.recv(1024).decode("UTF-8")
for i in srvmsg.split("\n")[:-1]:
i = i.split()
if i[0] == "PING":
s.send(bytes("PONG %s\n" % i[1], "UTF-8"))
s.send(bytes("JOIN %s\n" % config.room, "UTF-8"));
if i[1] == "PRIVMSG":
for item in config.nicks:
if item in i[3:]:
message = (":%s" % markov.speak())
message.lstrip(":")
time.sleep(4)
s.send(bytes("PRIVMSG %s %s \n" % ("%s" % config.room, message), "UTF-8"))

30
mark → markov.py

@ -2,11 +2,11 @@
from random import randint as randint
import random
#TODO: do not output lines directly from source. original only
#TODO: non capitalised seeds
#TODO new seeds in general
def parser(textfile):
wordList = textfile.replace('\n','_').split(" ")
wordList = wordList[0:-1]
#print("wordlist is: ", wordList)
return wordList
return textfile.replace('\n',' ').split()[0:-1]
class Grapher:
@ -55,16 +55,16 @@ def sentence(d):
s += ' '
return s
with open("corpus.txt","r") as f:
text = f.read()
def speak():
with open("corpus.txt","r") as f:
text = f.read()
g = Grapher()
d = g.graph(parser(text),2)
#g.dictPrint(d)
p = ''
for i in range(10):
y = sentence(d)
p += y
print(p.replace('_',' '))
g = Grapher()
d = g.graph(parser(text),2)
#g.dictPrint(d)
p = ''
for i in range(1):
y = sentence(d)
p += y
return (p[:-2])
Loading…
Cancel
Save