Compare commits

...

3 commits

4 changed files with 2717 additions and 0 deletions

2
bot.py
View file

@ -83,6 +83,7 @@ class bot(bare.bot):
for line in f.readlines():
TMFeed.extend([line.strip().split()])
self.markov = MarkovBot(TMFeed)
conf.prefix = (conf.servers[server]["prefix"] if "prefix" in conf.servers[server] else ".")
self.log(f"Start init for {self.server}")
def connect(self) -> None:
@ -320,6 +321,7 @@ class bot(bare.bot):
if "interval" in conf.servers[self.server]
else 50
)
conf.prefix = (conf.servers[server]["prefix"] if "prefix" in conf.servers[server] else ".")
reload(cmds)
reload(handlers)
self.msg("Reloaded successfully", chan)

View file

@ -67,6 +67,7 @@ servers: dict[str, dict[str, Any]] = {
"#firepup650": 0,
},
"admins": ["firepup650"],
"prefix": "!"
},
}
admin_hosts: list[str] = ["firepup.firepi", "47.221.227.180"]

51
markov.py Normal file
View file

@ -0,0 +1,51 @@
import random
from typing import Union
class MarkovBot:
def __init__(self, text: list[list[str]]) -> None:
self.text = text
self.chains = {}
self.__build_chains()
def __build_chains(self) -> None:
for i in range(len(self.text)):
text = self.text[i]
for j in range(len(text) - 1):
current_word = text[j]
next_word = text[j + 1]
if current_word not in self.chains:
self.chains[current_word] = {}
if next_word not in self.chains[current_word]:
self.chains[current_word][next_word] = 0
self.chains[current_word][next_word] += 1
def generate_text(self, word: Union[str, None] = None) -> str:
if not word:
current_word = random.choice(list(self.chains.keys()))
else:
current_word = word
generated_text = current_word
while current_word in self.chains:
next_word = random.choices(
list(self.chains[current_word].keys()),
weights=list(self.chains[current_word].values()),
)[0]
generated_text += " " + next_word
current_word = next_word
return generated_text
def generate_from_sentence(self, msg: Union[str, None] = None) -> str:
if not msg:
word = random.choice(list(self.chains.keys()))
else:
word = random.choice(msg.split())
if (for_word := self.generate_text(word)) != word:
return for_word
else:
return self.generate_text()

File diff suppressed because it is too large Load diff