mirror of
https://github.com/house-of-vanity/conf_bot.git
synced 2025-07-07 06:44:06 +00:00
Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
9b853f6809 | |||
40364735e0 | |||
cded7272d2 | |||
9a6bb39440 | |||
92686ed13d | |||
7f1f542be2 | |||
e09ffd6fa6 | |||
a80b915d10 | |||
a6d7903c57 | |||
b990f3eec8 | |||
62ad832396 | |||
7e7a4e3cc6 | |||
7f4d4ced56 | |||
e1e6ee1e9d | |||
d406ec14b4 | |||
a86b2c3b8e | |||
c04a5a9933 | |||
e707292465 | |||
1b9a37c267 | |||
9806a379f4 | |||
2b0b563a16 | |||
d71da08eff | |||
7428d1df51 | |||
c6f8876c2e | |||
1c0a3bd582 | |||
3fe8f87df8 | |||
31ce4d15cf | |||
7320a10b51 | |||
2eed876e6e | |||
977f918baa | |||
643ccfafbc | |||
3aa7982116 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -4,3 +4,8 @@ assets/cert*
|
|||||||
main.db
|
main.db
|
||||||
main.db-journal
|
main.db-journal
|
||||||
settings.ini
|
settings.ini
|
||||||
|
code.png
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*.allah
|
||||||
|
.vscode/settings.json
|
||||||
|
23
README.md
23
README.md
@ -1,10 +1,29 @@
|
|||||||
# Full burst ultimate storm revolution conf_bot
|
# Full burst ultimate storm revolution Telegram Conference Bot
|
||||||
|
|
||||||
# Create your own spy bot in Telegram ¯\_(ツ)_/¯
|
# Create your own spy bot in Telegram ¯\_(ツ)_/¯
|
||||||
|
|
||||||
This bot is able to get every message in your group, log it and send simple stat about top 10 used words.
|
This bot is able to get every message in your group, log it and send simple stat about top 10 used words.
|
||||||
Also bot can summon every active member of group with @here command.
|
|
||||||
|
|
||||||
|
|
||||||
|
/code - highlight any code snippet following command. There is lexer guesser but you are able to specify language by adding last line comment like this:
|
||||||
|
```
|
||||||
|
/code
|
||||||
|
class Cat {
|
||||||
|
constructor(name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function get_name(any_object) {
|
||||||
|
console.log(any_object.name);
|
||||||
|
}
|
||||||
|
var my_cat = new Cat('Cassandra');
|
||||||
|
get_name(my_cat)
|
||||||
|
#js
|
||||||
|
```
|
||||||
|
/sql - perform an SQL request to internal bot SQLite database. Any WRITE requests are prohibited.
|
||||||
|
/stat - your top 10 words in conf.
|
||||||
|
|
||||||
|
Also bot can summon every active member of group with @here command or just with mentioning bot username like @test_huy_bot .
|
||||||
**Copyright**
|
**Copyright**
|
||||||
|
|
||||||
*As probabilistic morphological analyzer (PMA) this bot uses mystem app, which developed by yandex and provided as binary package.*
|
*As probabilistic morphological analyzer (PMA) this bot uses mystem app, which developed by yandex and provided as binary package.*
|
||||||
|
@ -1 +1,2 @@
|
|||||||
openssl req -newkey rsa:2048 -sha256 -nodes -keyout cert.key -x509 -days 365 -out cert.pem -subj /C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=hexor.ru
|
openssl req -newkey rsa:2048 -sha256 -nodes -keyout cert.key -x509 -days 3650 -out cert.pem -subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=des-rkn.hexor.ru"
|
||||||
|
|
||||||
|
@ -1,43 +1,45 @@
|
|||||||
BEGIN TRANSACTION;
|
CREATE TABLE `word` (
|
||||||
-- DROP TABLE IF EXISTS `word`;
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
CREATE TABLE IF NOT EXISTS `word` (
|
`word` TEXT UNIQUE
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
`word` TEXT UNIQUE
|
|
||||||
);
|
);
|
||||||
-- DROP TABLE IF EXISTS `user`;
|
CREATE TABLE sqlite_sequence(name,seq);
|
||||||
CREATE TABLE IF NOT EXISTS `user` (
|
CREATE TABLE `user` (
|
||||||
`id` INTEGER NOT NULL UNIQUE,
|
`id` INTEGER NOT NULL UNIQUE,
|
||||||
`username` TEXT NOT NULL,
|
`username` TEXT NOT NULL,
|
||||||
`first_name` INTEGER NOT NULL,
|
`first_name` INTEGER NOT NULL,
|
||||||
`last_name` INTEGER NOT NULL,
|
`last_name` INTEGER NOT NULL,
|
||||||
`date` INTEGER NOT NULL,
|
`date` INTEGER NOT NULL,
|
||||||
PRIMARY KEY(`id`)
|
PRIMARY KEY(`id`)
|
||||||
);
|
);
|
||||||
-- DROP TABLE IF EXISTS `reset`;
|
CREATE TABLE `conf` (
|
||||||
CREATE TABLE IF NOT EXISTS `reset` (
|
`id` NUMERIC NOT NULL UNIQUE,
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`title` TEXT,
|
||||||
`user_id` INTEGER,
|
`date` INTEGER NOT NULL,
|
||||||
`conf_id` INTEGER,
|
PRIMARY KEY(`id`)
|
||||||
`date` INTEGER,
|
|
||||||
`relation_id` INTEGER,
|
|
||||||
FOREIGN KEY(`user_id`) REFERENCES `user`(`id`)
|
|
||||||
);
|
);
|
||||||
-- DROP TABLE IF EXISTS `relations`;
|
CREATE TABLE IF NOT EXISTS "relations" (
|
||||||
CREATE TABLE IF NOT EXISTS `relations` (
|
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
`word_id` INTEGER NOT NULL,
|
||||||
`word_id` INTEGER NOT NULL,
|
`user_id` INTEGER NOT NULL,
|
||||||
`user_id` INTEGER NOT NULL,
|
`conf_id` INTEGER NOT NULL,
|
||||||
`conf_id` INTEGER NOT NULL,
|
`date` INTEGER NOT NULL, `msg_id` INTEGER NULL,
|
||||||
`date` INTEGER NOT NULL,
|
FOREIGN KEY(`word_id`) REFERENCES `word`(`id`) ON DELETE CASCADE,
|
||||||
FOREIGN KEY(`conf_id`) REFERENCES `conf`(`id`),
|
FOREIGN KEY(`user_id`) REFERENCES `user`(`id`),
|
||||||
FOREIGN KEY(`word_id`) REFERENCES `word`(`id`),
|
FOREIGN KEY(`conf_id`) REFERENCES `conf`(`id`)
|
||||||
FOREIGN KEY(`user_id`) REFERENCES `user`(`id`)
|
|
||||||
);
|
);
|
||||||
-- DROP TABLE IF EXISTS `conf`;
|
CREATE TABLE `reset` (
|
||||||
CREATE TABLE IF NOT EXISTS `conf` (
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`id` NUMERIC NOT NULL UNIQUE,
|
`user_id` INTEGER,
|
||||||
`title` TEXT,
|
`conf_id` INTEGER,
|
||||||
`date` INTEGER NOT NULL,
|
`date` INTEGER,
|
||||||
PRIMARY KEY(`id`)
|
`relation_id` INTEGER,
|
||||||
|
FOREIGN KEY(`user_id`) REFERENCES `user`(`id`)
|
||||||
);
|
);
|
||||||
COMMIT;
|
CREATE TABLE `alert` (
|
||||||
|
`conf_id`TEXT NOT NULL,
|
||||||
|
`user_id`TEXT NOT NULL,
|
||||||
|
`created`TEXT NOT NULL,
|
||||||
|
`time`TEXT NOT NULL,
|
||||||
|
`message`TEXT
|
||||||
|
);
|
||||||
|
CREATE TABLE `xxx_message` (`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `text`TEXT UNIQUE NULL);
|
||||||
|
@ -422,3 +422,6 @@ ThreadTopBot
|
|||||||
многочисленные
|
многочисленные
|
||||||
многочисленный
|
многочисленный
|
||||||
ага
|
ага
|
||||||
|
делать
|
||||||
|
писать
|
||||||
|
бот
|
115
database.py
115
database.py
@ -1,5 +1,6 @@
|
|||||||
import datetime as dt
|
import datetime as dt
|
||||||
|
|
||||||
|
|
||||||
class DataBase:
|
class DataBase:
|
||||||
def __init__(self, basefile, scheme):
|
def __init__(self, basefile, scheme):
|
||||||
import sqlite3
|
import sqlite3
|
||||||
@ -34,12 +35,38 @@ class DataBase:
|
|||||||
sql = "SELECT id FROM word WHERE word = '%s'" % word
|
sql = "SELECT id FROM word WHERE word = '%s'" % word
|
||||||
return(self.execute(sql)[0][0])
|
return(self.execute(sql)[0][0])
|
||||||
|
|
||||||
|
def get_alert(self):
|
||||||
|
now = dt.datetime.now().strftime("%H%M")
|
||||||
|
sql = "SELECT * FROM alert WHERE time = '%s'" % now
|
||||||
|
alerts = self.execute(sql)
|
||||||
|
sql = "DELETE FROM alert WHERE time = '%s'" % now
|
||||||
|
self.execute(sql)
|
||||||
|
return alerts
|
||||||
|
|
||||||
def add_user(self,
|
def add_user(self,
|
||||||
username,
|
username,
|
||||||
user_id,
|
user_id,
|
||||||
first_name,
|
first_name,
|
||||||
last_name):
|
last_name):
|
||||||
date = int(dt.datetime.now().strftime("%s"))
|
date = int(dt.datetime.now().strftime("%s"))
|
||||||
|
try:
|
||||||
|
sql = """
|
||||||
|
UPDATE user
|
||||||
|
SET
|
||||||
|
username = '%s',
|
||||||
|
first_name = '%s',
|
||||||
|
last_name = '%s'
|
||||||
|
WHERE
|
||||||
|
id = '%s'
|
||||||
|
""" % (
|
||||||
|
username,
|
||||||
|
first_name,
|
||||||
|
last_name,
|
||||||
|
user_id
|
||||||
|
)
|
||||||
|
self.execute(sql)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
sql = """INSERT OR IGNORE INTO
|
sql = """INSERT OR IGNORE INTO
|
||||||
user('id', 'username', 'first_name', 'last_name', 'date')
|
user('id', 'username', 'first_name', 'last_name', 'date')
|
||||||
VALUES ('%s','%s','%s','%s','%s')""" % (
|
VALUES ('%s','%s','%s','%s','%s')""" % (
|
||||||
@ -62,21 +89,42 @@ class DataBase:
|
|||||||
)
|
)
|
||||||
self.execute(sql)
|
self.execute(sql)
|
||||||
|
|
||||||
def add_relation(self, word, user_id, conf_id):
|
def add_relation(self, word, user_id, conf_id, text):
|
||||||
word_id = self.save_word(word)
|
word_id = self.save_word(word)
|
||||||
date = int(dt.datetime.now().strftime("%s"))
|
date = int(dt.datetime.now().strftime("%s"))
|
||||||
|
sql2 = "INSERT OR IGNORE INTO xxx_message('text') VALUES ('%s')" % text
|
||||||
|
self.execute(sql2)
|
||||||
|
sql3 = "SELECT id FROM `xxx_message` WHERE text = '%s'" % text
|
||||||
|
msg_id = self.execute(sql3)[0][0]
|
||||||
sql = """INSERT OR IGNORE INTO
|
sql = """INSERT OR IGNORE INTO
|
||||||
relations('word_id', 'user_id', 'conf_id', 'date')
|
relations('word_id', 'user_id', 'conf_id', 'msg_id', 'date')
|
||||||
VALUES ('%s','%s','%s','%s')""" % (
|
VALUES ('%s','%s','%s','%s', '%s')""" % (
|
||||||
word_id,
|
word_id,
|
||||||
user_id,
|
user_id,
|
||||||
conf_id,
|
conf_id,
|
||||||
|
msg_id,
|
||||||
date
|
date
|
||||||
)
|
)
|
||||||
self.execute(sql)
|
self.execute(sql)
|
||||||
|
|
||||||
|
def add_alert(self, user_id, conf_id, alert_time, message):
|
||||||
|
date = int(dt.datetime.now().strftime("%s"))
|
||||||
|
print(alert_time)
|
||||||
|
if alert_time[0] == '+':
|
||||||
|
alert_time = (dt.datetime.now() + dt.timedelta(minutes=int(alert_time[1:]))).strftime("%H%M")
|
||||||
|
sql = """INSERT OR IGNORE INTO
|
||||||
|
alert('conf_id', 'user_id', 'created', 'time', 'message')
|
||||||
|
VALUES ('%s','%s','%s','%s','%s')""" % (
|
||||||
|
conf_id,
|
||||||
|
user_id,
|
||||||
|
date,
|
||||||
|
alert_time,
|
||||||
|
message
|
||||||
|
)
|
||||||
|
self.execute(sql)
|
||||||
|
|
||||||
def get_top(self, user_id, conf_id, limit=10):
|
def get_top(self, user_id, conf_id, limit=10):
|
||||||
sql= """
|
sql = """
|
||||||
SELECT w.word, COUNT(*) as count FROM relations r
|
SELECT w.word, COUNT(*) as count FROM relations r
|
||||||
LEFT JOIN word w ON w.id = r.word_id
|
LEFT JOIN word w ON w.id = r.word_id
|
||||||
LEFT JOIN `user` u ON u.id = r.user_id
|
LEFT JOIN `user` u ON u.id = r.user_id
|
||||||
@ -98,9 +146,42 @@ class DataBase:
|
|||||||
result = self.execute(sql)
|
result = self.execute(sql)
|
||||||
return(result)
|
return(result)
|
||||||
|
|
||||||
|
def all_conf_users(self, conf_id):
|
||||||
|
sql = """
|
||||||
|
SELECT DISTINCT(u.username), u.first_name, u.id FROM relations r
|
||||||
|
LEFT JOIN user u
|
||||||
|
ON u.id = r.user_id
|
||||||
|
LEFT JOIN conf c
|
||||||
|
ON r.conf_id = c.id
|
||||||
|
WHERE c.id = '%s'
|
||||||
|
""" % (
|
||||||
|
conf_id
|
||||||
|
)
|
||||||
|
result = self.execute(sql)
|
||||||
|
return(result)
|
||||||
|
|
||||||
|
def get_random_word(self, count=1, like="%"):
|
||||||
|
sql = "SELECT word FROM word WHERE word LIKE '%s' ORDER BY random() LIMIT %s" % (like, count)
|
||||||
|
result = self.execute(sql)
|
||||||
|
return(result)
|
||||||
|
|
||||||
|
def get_random_message(self, conf_id=None, count=1):
|
||||||
|
if not conf_id:
|
||||||
|
print('get random message from all DB, count %s' % count)
|
||||||
|
sql = "SELECT text FROM xxx_message ORDER BY RANDOM() LIMIT %s" % count
|
||||||
|
else:
|
||||||
|
print('get random message from %s, count: %s' % (conf_id, count))
|
||||||
|
sql = """SELECT x.text FROM xxx_message x LEFT JOIN relations r ON r.msg_id == x.id
|
||||||
|
WHERE r.conf_id = '%s' ORDER BY RANDOM() DESC LIMIT %s""" % (conf_id, count)
|
||||||
|
result = self.execute(sql)
|
||||||
|
messages = list()
|
||||||
|
for msg in result:
|
||||||
|
messages.append(msg[0])
|
||||||
|
return(messages)
|
||||||
|
|
||||||
def here(self, user_id, conf_id):
|
def here(self, user_id, conf_id):
|
||||||
sql= """
|
sql = """
|
||||||
SELECT DISTINCT(u.username) FROM relations r
|
SELECT DISTINCT(u.username), u.id, u.first_name FROM relations r
|
||||||
LEFT JOIN user u
|
LEFT JOIN user u
|
||||||
ON u.id = r.user_id
|
ON u.id = r.user_id
|
||||||
LEFT JOIN conf c
|
LEFT JOIN conf c
|
||||||
@ -129,17 +210,17 @@ class DataBase:
|
|||||||
|
|
||||||
def command(self, sql):
|
def command(self, sql):
|
||||||
if 'DELETE' in sql.upper() \
|
if 'DELETE' in sql.upper() \
|
||||||
or 'INSERT' in sql.upper() \
|
or 'INSERT' in sql.upper() \
|
||||||
or 'UPDATE' in sql.upper() \
|
or 'UPDATE' in sql.upper() \
|
||||||
or 'DROP' in sql.upper() \
|
or 'DROP' in sql.upper() \
|
||||||
or 'CREATE' in sql.upper() \
|
or 'CREATE' in sql.upper() \
|
||||||
or 'ALTER' in sql.upper():
|
or 'ALTER' in sql.upper():
|
||||||
return('gtfo')
|
return('gtfo')
|
||||||
try:
|
try:
|
||||||
if 'LIMIT' in sql.upper()[-9:]:
|
if 'LIMIT' in sql.upper()[-9:]:
|
||||||
result = self.execute(sql)
|
result = self.execute(sql)
|
||||||
else:
|
else:
|
||||||
result = self.execute(sql + ' limit 20')
|
result = self.execute(sql + ' limit 20')
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
result = err
|
result = err
|
||||||
return(result)
|
return(result)
|
||||||
|
7
markov/__init__.py
Normal file
7
markov/__init__.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
"""Markov chain text generator"""
|
||||||
|
|
||||||
|
from .gen import MarkovChain
|
||||||
|
from .simple import get
|
||||||
|
|
||||||
|
__all__ = ["MarkovChain", "get"]
|
||||||
|
|
74
markov/gen.py
Normal file
74
markov/gen.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
from .histograms import Dictogram
|
||||||
|
import random
|
||||||
|
from collections import deque
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
class MarkovChain:
|
||||||
|
def __init__(self, text=str()):
|
||||||
|
self.length = 25
|
||||||
|
self.text = text
|
||||||
|
self.text_list = None
|
||||||
|
self._prepare_list()
|
||||||
|
self.model = self._gen_model()
|
||||||
|
|
||||||
|
def _prepare_list(self):
|
||||||
|
if isinstance(self.text, str):
|
||||||
|
self._clean_text()
|
||||||
|
self.text_list = self.text.split()
|
||||||
|
else:
|
||||||
|
raise TypeError
|
||||||
|
|
||||||
|
def _clean_text(self):
|
||||||
|
text = self.text.replace('—','')
|
||||||
|
text = self.text.replace('«','')
|
||||||
|
text = self.text.replace('»','')
|
||||||
|
text = self.text.replace('(','')
|
||||||
|
text = self.text.replace(')','')
|
||||||
|
text = self.text.replace('.','')
|
||||||
|
text = self.text.replace(',','')
|
||||||
|
self.text = text
|
||||||
|
print(self.text)
|
||||||
|
|
||||||
|
def _gen_model(self):
|
||||||
|
data = self.text_list
|
||||||
|
if data is None:
|
||||||
|
raise TypeError
|
||||||
|
markov_model = dict()
|
||||||
|
for i in range(0, len(data)-1):
|
||||||
|
if data[i] in markov_model:
|
||||||
|
markov_model[data[i]].update([data[i+1]])
|
||||||
|
else:
|
||||||
|
markov_model[data[i]] = Dictogram([data[i+1]])
|
||||||
|
return markov_model
|
||||||
|
|
||||||
|
def _generate_random_start(self):
|
||||||
|
model = self.model
|
||||||
|
# Чтобы сгенерировать любое начальное слово, раскомментируйте строку:
|
||||||
|
return random.choice(list(model.keys()))
|
||||||
|
|
||||||
|
# Чтобы сгенерировать "правильное" начальное слово, используйте код ниже:
|
||||||
|
# Правильные начальные слова - это те, что являлись началом предложений в корпусе
|
||||||
|
if 'END' in model:
|
||||||
|
seed_word = 'END'
|
||||||
|
while seed_word == 'END':
|
||||||
|
seed_word = model['END'].return_weighted_random_word()
|
||||||
|
return seed_word
|
||||||
|
return random.choice(list(model.keys()))
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_sentence(self):
|
||||||
|
markov_model = self.model
|
||||||
|
length = self.length if len(self.text_list) > self.length else len(self.text_list) - 1
|
||||||
|
current_word = self._generate_random_start()
|
||||||
|
sentence = [current_word]
|
||||||
|
for i in range(0, length):
|
||||||
|
try:
|
||||||
|
current_dictogram = markov_model[current_word]
|
||||||
|
random_weighted_word = current_dictogram.return_weighted_random_word()
|
||||||
|
current_word = random_weighted_word
|
||||||
|
sentence.append(current_word)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
sentence[0] = sentence[0].capitalize()
|
||||||
|
return ' '.join(sentence) + '.'
|
49
markov/histograms.py
Normal file
49
markov/histograms.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
class Dictogram(dict):
|
||||||
|
def __init__(self, iterable=None):
|
||||||
|
# Инициализируем наше распределение как новый объект класса,
|
||||||
|
# добавляем имеющиеся элементы
|
||||||
|
super(Dictogram, self).__init__()
|
||||||
|
self.types = 0 # число уникальных ключей в распределении
|
||||||
|
self.tokens = 0 # общее количество всех слов в распределении
|
||||||
|
if iterable:
|
||||||
|
self.update(iterable)
|
||||||
|
|
||||||
|
def update(self, iterable):
|
||||||
|
# Обновляем распределение элементами из имеющегося
|
||||||
|
# итерируемого набора данных
|
||||||
|
for item in iterable:
|
||||||
|
if item in self:
|
||||||
|
self[item] += 1
|
||||||
|
self.tokens += 1
|
||||||
|
else:
|
||||||
|
self[item] = 1
|
||||||
|
self.types += 1
|
||||||
|
self.tokens += 1
|
||||||
|
|
||||||
|
def count(self, item):
|
||||||
|
# Возвращаем значение счетчика элемента, или 0
|
||||||
|
if item in self:
|
||||||
|
return self[item]
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def return_random_word(self):
|
||||||
|
random_key = random.sample(self, 1)
|
||||||
|
# Другой способ:
|
||||||
|
# random.choice(histogram.keys())
|
||||||
|
return random_key[0]
|
||||||
|
|
||||||
|
def return_weighted_random_word(self):
|
||||||
|
# Сгенерировать псевдослучайное число между 0 и (n-1),
|
||||||
|
# где n - общее число слов
|
||||||
|
random_int = random.randint(0, self.tokens-1)
|
||||||
|
index = 0
|
||||||
|
list_of_keys = list(self.keys())
|
||||||
|
# вывести 'случайный индекс:', random_int
|
||||||
|
for i in range(0, self.types):
|
||||||
|
index += self[list_of_keys[i]]
|
||||||
|
# вывести индекс
|
||||||
|
if(index > random_int):
|
||||||
|
# вывести list_of_keys[i]
|
||||||
|
return list_of_keys[i]
|
90
markov/simple.py
Normal file
90
markov/simple.py
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
import random
|
||||||
|
from collections import deque
|
||||||
|
import re
|
||||||
|
|
||||||
|
class Dictogram(dict):
|
||||||
|
def __init__(self, iterable=None):
|
||||||
|
super(Dictogram, self).__init__()
|
||||||
|
self.types = 0
|
||||||
|
self.tokens = 0
|
||||||
|
if iterable:
|
||||||
|
self.update(iterable)
|
||||||
|
|
||||||
|
def update(self, iterable):
|
||||||
|
for item in iterable:
|
||||||
|
if item in self:
|
||||||
|
self[item] += 1
|
||||||
|
self.tokens += 1
|
||||||
|
else:
|
||||||
|
self[item] = 1
|
||||||
|
self.types += 1
|
||||||
|
self.tokens += 1
|
||||||
|
|
||||||
|
def count(self, item):
|
||||||
|
if item in self:
|
||||||
|
return self[item]
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def return_random_word(self):
|
||||||
|
random_key = random.sample(self, 1)
|
||||||
|
return random_key[0]
|
||||||
|
|
||||||
|
def return_weighted_random_word(self):
|
||||||
|
random_int = random.randint(0, self.tokens-1)
|
||||||
|
index = 0
|
||||||
|
list_of_keys = list(self.keys())
|
||||||
|
for i in range(0, self.types):
|
||||||
|
index += self[list_of_keys[i]]
|
||||||
|
if(index > random_int):
|
||||||
|
return list_of_keys[i]
|
||||||
|
|
||||||
|
def get(text):
|
||||||
|
def generate_random_start(model):
|
||||||
|
if 'END' in model:
|
||||||
|
seed_word = 'END'
|
||||||
|
while seed_word == 'END':
|
||||||
|
seed_word = model['END'].return_weighted_random_word()
|
||||||
|
return seed_word
|
||||||
|
return random.choice(list(model.keys()))
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_sentence(length, markov_model):
|
||||||
|
current_word = generate_random_start(markov_model)
|
||||||
|
sentence = [current_word]
|
||||||
|
for i in range(0, length):
|
||||||
|
try:
|
||||||
|
current_dictogram = markov_model[current_word]
|
||||||
|
random_weighted_word = current_dictogram.return_weighted_random_word()
|
||||||
|
current_word = random_weighted_word
|
||||||
|
sentence.append(current_word)
|
||||||
|
except:
|
||||||
|
break
|
||||||
|
sentence[0] = sentence[0].capitalize()
|
||||||
|
return ' '.join(sentence) + '.'
|
||||||
|
return sentence
|
||||||
|
|
||||||
|
def make_markov_model(data):
|
||||||
|
markov_model = dict()
|
||||||
|
|
||||||
|
for i in range(0, len(data)-1):
|
||||||
|
if data[i] in markov_model:
|
||||||
|
markov_model[data[i]].update([data[i+1]])
|
||||||
|
else:
|
||||||
|
markov_model[data[i]] = Dictogram([data[i+1]])
|
||||||
|
return markov_model
|
||||||
|
|
||||||
|
# simple cleanup
|
||||||
|
text = text.replace('—','')
|
||||||
|
text = text.replace('«','')
|
||||||
|
text = text.replace('»','')
|
||||||
|
text = text.replace('(','')
|
||||||
|
text = text.replace(')','')
|
||||||
|
text = "START " + text
|
||||||
|
text = text.replace('.', ' END')
|
||||||
|
|
||||||
|
text_list = text.split()
|
||||||
|
model = make_markov_model(text_list)
|
||||||
|
|
||||||
|
generated = generate_random_sentence(random.randint(5,30), model)
|
||||||
|
generated = generated.replace(' END', '.')
|
||||||
|
return generated
|
76
puller.py
Normal file
76
puller.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import logging
|
||||||
|
import settings
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
#from webhook import WebHook
|
||||||
|
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG,
|
||||||
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# catch ctrl+c
|
||||||
|
def signal_handler(signal, frame):
|
||||||
|
print('Exiting...')
|
||||||
|
settings.db.close()
|
||||||
|
sys.exit(0)
|
||||||
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
|
|
||||||
|
# Define a few command handlers. These usually take the two arguments bot and
|
||||||
|
# update. Error handlers also receive the raised TelegramError object in error.
|
||||||
|
def start(update, context):
|
||||||
|
"""Send a message when the command /start is issued."""
|
||||||
|
update.message.reply_text('Hi!')
|
||||||
|
|
||||||
|
|
||||||
|
def help(update, context):
|
||||||
|
"""Send a message when the command /help is issued."""
|
||||||
|
update.message.reply_text('Help!')
|
||||||
|
|
||||||
|
|
||||||
|
def echo(update, context):
|
||||||
|
"""Echo the user message."""
|
||||||
|
update.message.reply_text(update.message.text)
|
||||||
|
|
||||||
|
|
||||||
|
def error(update, context):
|
||||||
|
"""Log Errors caused by Updates."""
|
||||||
|
logger.warning('Update "%s" caused error "%s"', update, context.error)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Start the bot."""
|
||||||
|
# Create the Updater and pass it your bot's token.
|
||||||
|
# Make sure to set use_context=True to use the new context based callbacks
|
||||||
|
# Post version 12 this will no longer be necessary
|
||||||
|
token = settings.parser.get('bot', 'telegram_key')
|
||||||
|
updater = Updater(token, use_context=True)
|
||||||
|
|
||||||
|
# Get the dispatcher to register handlers
|
||||||
|
dp = updater.dispatcher
|
||||||
|
|
||||||
|
# on different commands - answer in Telegram
|
||||||
|
dp.add_handler(CommandHandler("start", start))
|
||||||
|
dp.add_handler(CommandHandler("help", help))
|
||||||
|
|
||||||
|
# on noncommand i.e message - echo the message on Telegram
|
||||||
|
dp.add_handler(MessageHandler(Filters.text, echo))
|
||||||
|
|
||||||
|
# log all errors
|
||||||
|
dp.add_error_handler(error)
|
||||||
|
|
||||||
|
# Start the Bot
|
||||||
|
updater.start_polling()
|
||||||
|
|
||||||
|
# Run the bot until you press Ctrl-C or the process receives SIGINT,
|
||||||
|
# SIGTERM or SIGABRT. This should be used most of the time, since
|
||||||
|
# start_polling() is non-blocking and will stop the bot gracefully.
|
||||||
|
updater.idle()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@ -12,4 +12,4 @@ db = DataBase(
|
|||||||
scheme='assets/main.db.sql')
|
scheme='assets/main.db.sql')
|
||||||
|
|
||||||
global worker
|
global worker
|
||||||
worker = MessageWorker(db = db)
|
worker = MessageWorker(db=db)
|
||||||
|
87
simple.py
Normal file
87
simple.py
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
import random
|
||||||
|
from collections import deque
|
||||||
|
import re
|
||||||
|
|
||||||
|
class Dictogram(dict):
|
||||||
|
def __init__(self, iterable=None):
|
||||||
|
super(Dictogram, self).__init__()
|
||||||
|
self.types = 0
|
||||||
|
self.tokens = 0
|
||||||
|
if iterable:
|
||||||
|
self.update(iterable)
|
||||||
|
|
||||||
|
def update(self, iterable):
|
||||||
|
for item in iterable:
|
||||||
|
if item in self:
|
||||||
|
self[item] += 1
|
||||||
|
self.tokens += 1
|
||||||
|
else:
|
||||||
|
self[item] = 1
|
||||||
|
self.types += 1
|
||||||
|
self.tokens += 1
|
||||||
|
|
||||||
|
def count(self, item):
|
||||||
|
if item in self:
|
||||||
|
return self[item]
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def return_random_word(self):
|
||||||
|
random_key = random.sample(self, 1)
|
||||||
|
return random_key[0]
|
||||||
|
|
||||||
|
def return_weighted_random_word(self):
|
||||||
|
random_int = random.randint(0, self.tokens-1)
|
||||||
|
index = 0
|
||||||
|
list_of_keys = list(self.keys())
|
||||||
|
for i in range(0, self.types):
|
||||||
|
index += self[list_of_keys[i]]
|
||||||
|
if(index > random_int):
|
||||||
|
return list_of_keys[i]
|
||||||
|
|
||||||
|
def get(text):
|
||||||
|
def generate_random_start(model):
|
||||||
|
if 'END' in model:
|
||||||
|
seed_word = 'END'
|
||||||
|
while seed_word == 'END':
|
||||||
|
seed_word = model['END'].return_weighted_random_word()
|
||||||
|
return seed_word
|
||||||
|
return random.choice(list(model.keys()))
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_sentence(length, markov_model):
|
||||||
|
current_word = generate_random_start(markov_model)
|
||||||
|
sentence = [current_word]
|
||||||
|
for i in range(0, length):
|
||||||
|
current_dictogram = markov_model[current_word]
|
||||||
|
random_weighted_word = current_dictogram.return_weighted_random_word()
|
||||||
|
current_word = random_weighted_word
|
||||||
|
sentence.append(current_word)
|
||||||
|
sentence[0] = sentence[0].capitalize()
|
||||||
|
return ' '.join(sentence) + '.'
|
||||||
|
return sentence
|
||||||
|
|
||||||
|
def make_markov_model(data):
|
||||||
|
markov_model = dict()
|
||||||
|
|
||||||
|
for i in range(0, len(data)-1):
|
||||||
|
if data[i] in markov_model:
|
||||||
|
markov_model[data[i]].update([data[i+1]])
|
||||||
|
else:
|
||||||
|
markov_model[data[i]] = Dictogram([data[i+1]])
|
||||||
|
return markov_model
|
||||||
|
|
||||||
|
# simple cleanup
|
||||||
|
text = text.replace('—','')
|
||||||
|
text = text.replace('«','')
|
||||||
|
text = text.replace('»','')
|
||||||
|
text = text.replace('(','')
|
||||||
|
text = text.replace(')','')
|
||||||
|
text = "START " + text
|
||||||
|
text = text.replace('.', ' END')
|
||||||
|
|
||||||
|
text_list = text.split()
|
||||||
|
model = make_markov_model(text_list)
|
||||||
|
|
||||||
|
generated = generate_random_sentence(50, model)
|
||||||
|
generated = generated.replace(' END', '.')
|
||||||
|
print(generated)
|
822
vim-session
Normal file
822
vim-session
Normal file
@ -0,0 +1,822 @@
|
|||||||
|
let SessionLoad = 1
|
||||||
|
if &cp | set nocp | endif
|
||||||
|
map Q gq
|
||||||
|
let s:cpo_save=&cpo
|
||||||
|
set cpo&vim
|
||||||
|
vmap gx <Plug>NetrwBrowseXVis
|
||||||
|
nmap gx <Plug>NetrwBrowseX
|
||||||
|
vnoremap <silent> <Plug>NetrwBrowseXVis :call netrw#BrowseXVis()
|
||||||
|
nnoremap <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>')),netrw#CheckIfRemote())
|
||||||
|
inoremap u
|
||||||
|
let &cpo=s:cpo_save
|
||||||
|
unlet s:cpo_save
|
||||||
|
set background=dark
|
||||||
|
set backspace=indent,eol,start
|
||||||
|
set display=truncate
|
||||||
|
set fileencodings=ucs-bom,utf-8,default,latin1
|
||||||
|
set helplang=en
|
||||||
|
set history=200
|
||||||
|
set incsearch
|
||||||
|
set langnoremap
|
||||||
|
set nolangremap
|
||||||
|
set nomodeline
|
||||||
|
set nrformats=bin,hex
|
||||||
|
set ruler
|
||||||
|
set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim80,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after
|
||||||
|
set scrolloff=5
|
||||||
|
set showcmd
|
||||||
|
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
|
||||||
|
set ttimeout
|
||||||
|
set ttimeoutlen=100
|
||||||
|
set wildignore=*.pyc
|
||||||
|
set wildmenu
|
||||||
|
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
|
||||||
|
let v:this_session=expand("<sfile>:p")
|
||||||
|
silent only
|
||||||
|
cd ~/repos/conf_bot
|
||||||
|
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
|
||||||
|
let s:wipebuf = bufnr('%')
|
||||||
|
endif
|
||||||
|
set shortmess=aoO
|
||||||
|
badd +0 puller.py
|
||||||
|
badd +0 main.py
|
||||||
|
badd +0 settings.py
|
||||||
|
badd +0 webhook.py
|
||||||
|
badd +0 assets/settings.ini
|
||||||
|
badd +0 worker.py
|
||||||
|
argglobal
|
||||||
|
silent! argdel *
|
||||||
|
$argadd puller.py
|
||||||
|
set stal=2
|
||||||
|
edit puller.py
|
||||||
|
set splitbelow splitright
|
||||||
|
set nosplitbelow
|
||||||
|
set nosplitright
|
||||||
|
wincmd t
|
||||||
|
set winminheight=1 winheight=1 winminwidth=1 winwidth=1
|
||||||
|
argglobal
|
||||||
|
setlocal keymap=
|
||||||
|
setlocal noarabic
|
||||||
|
setlocal autoindent
|
||||||
|
setlocal backupcopy=
|
||||||
|
setlocal balloonexpr=
|
||||||
|
setlocal nobinary
|
||||||
|
setlocal nobreakindent
|
||||||
|
setlocal breakindentopt=
|
||||||
|
setlocal bufhidden=
|
||||||
|
setlocal buflisted
|
||||||
|
setlocal buftype=
|
||||||
|
setlocal nocindent
|
||||||
|
setlocal cinkeys=0{,0},0),:,!^F,o,O,e
|
||||||
|
setlocal cinoptions=
|
||||||
|
setlocal cinwords=if,else,while,do,for,switch
|
||||||
|
setlocal colorcolumn=
|
||||||
|
setlocal comments=b:#,fb:-
|
||||||
|
setlocal commentstring=#\ %s
|
||||||
|
setlocal complete=.,w,b,u,t,i
|
||||||
|
setlocal concealcursor=
|
||||||
|
setlocal conceallevel=0
|
||||||
|
setlocal completefunc=
|
||||||
|
setlocal nocopyindent
|
||||||
|
setlocal cryptmethod=
|
||||||
|
setlocal nocursorbind
|
||||||
|
setlocal nocursorcolumn
|
||||||
|
setlocal nocursorline
|
||||||
|
setlocal define=
|
||||||
|
setlocal dictionary=
|
||||||
|
setlocal nodiff
|
||||||
|
setlocal equalprg=
|
||||||
|
setlocal errorformat=
|
||||||
|
setlocal expandtab
|
||||||
|
if &filetype != 'python'
|
||||||
|
setlocal filetype=python
|
||||||
|
endif
|
||||||
|
setlocal fixendofline
|
||||||
|
setlocal foldcolumn=0
|
||||||
|
setlocal foldenable
|
||||||
|
setlocal foldexpr=0
|
||||||
|
setlocal foldignore=#
|
||||||
|
setlocal foldlevel=0
|
||||||
|
setlocal foldmarker={{{,}}}
|
||||||
|
setlocal foldmethod=manual
|
||||||
|
setlocal foldminlines=1
|
||||||
|
setlocal foldnestmax=20
|
||||||
|
setlocal foldtext=foldtext()
|
||||||
|
setlocal formatexpr=
|
||||||
|
setlocal formatoptions=tcq
|
||||||
|
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
|
||||||
|
setlocal formatprg=
|
||||||
|
setlocal grepprg=
|
||||||
|
setlocal iminsert=0
|
||||||
|
setlocal imsearch=-1
|
||||||
|
setlocal include=^\\s*\\(from\\|import\\)
|
||||||
|
setlocal includeexpr=substitute(v:fname,'\\.','/','g')
|
||||||
|
setlocal indentexpr=GetPythonIndent(v:lnum)
|
||||||
|
setlocal indentkeys=0{,0},:,!^F,o,O,e,<:>,=elif,=except
|
||||||
|
setlocal noinfercase
|
||||||
|
setlocal iskeyword=@,48-57,_,192-255
|
||||||
|
setlocal keywordprg=
|
||||||
|
setlocal nolinebreak
|
||||||
|
setlocal nolisp
|
||||||
|
setlocal lispwords=
|
||||||
|
setlocal nolist
|
||||||
|
setlocal makeencoding=
|
||||||
|
setlocal makeprg=
|
||||||
|
setlocal matchpairs=(:),{:},[:]
|
||||||
|
setlocal nomodeline
|
||||||
|
setlocal modifiable
|
||||||
|
setlocal nrformats=bin,hex
|
||||||
|
setlocal nonumber
|
||||||
|
setlocal numberwidth=4
|
||||||
|
setlocal omnifunc=python3complete#Complete
|
||||||
|
setlocal path=
|
||||||
|
setlocal nopreserveindent
|
||||||
|
setlocal nopreviewwindow
|
||||||
|
setlocal quoteescape=\\
|
||||||
|
setlocal noreadonly
|
||||||
|
setlocal norelativenumber
|
||||||
|
setlocal norightleft
|
||||||
|
setlocal rightleftcmd=search
|
||||||
|
setlocal noscrollbind
|
||||||
|
setlocal shiftwidth=4
|
||||||
|
setlocal noshortname
|
||||||
|
setlocal signcolumn=auto
|
||||||
|
setlocal nosmartindent
|
||||||
|
setlocal softtabstop=4
|
||||||
|
setlocal nospell
|
||||||
|
setlocal spellcapcheck=[.?!]\\_[\\])'\"\ \ ]\\+
|
||||||
|
setlocal spellfile=
|
||||||
|
setlocal spelllang=en
|
||||||
|
setlocal statusline=
|
||||||
|
setlocal suffixesadd=.py
|
||||||
|
setlocal swapfile
|
||||||
|
setlocal synmaxcol=3000
|
||||||
|
if &syntax != 'python'
|
||||||
|
setlocal syntax=python
|
||||||
|
endif
|
||||||
|
setlocal tabstop=8
|
||||||
|
setlocal tagcase=
|
||||||
|
setlocal tags=
|
||||||
|
setlocal termkey=
|
||||||
|
setlocal termsize=
|
||||||
|
setlocal textwidth=0
|
||||||
|
setlocal thesaurus=
|
||||||
|
setlocal noundofile
|
||||||
|
setlocal undolevels=-123456
|
||||||
|
setlocal nowinfixheight
|
||||||
|
setlocal nowinfixwidth
|
||||||
|
setlocal wrap
|
||||||
|
setlocal wrapmargin=0
|
||||||
|
silent! normal! zE
|
||||||
|
let s:l = 51 - ((50 * winheight(0) + 51) / 102)
|
||||||
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
|
exe s:l
|
||||||
|
normal! zt
|
||||||
|
51
|
||||||
|
normal! 027|
|
||||||
|
tabedit settings.py
|
||||||
|
set splitbelow splitright
|
||||||
|
set nosplitbelow
|
||||||
|
set nosplitright
|
||||||
|
wincmd t
|
||||||
|
set winminheight=1 winheight=1 winminwidth=1 winwidth=1
|
||||||
|
argglobal
|
||||||
|
setlocal keymap=
|
||||||
|
setlocal noarabic
|
||||||
|
setlocal autoindent
|
||||||
|
setlocal backupcopy=
|
||||||
|
setlocal balloonexpr=
|
||||||
|
setlocal nobinary
|
||||||
|
setlocal nobreakindent
|
||||||
|
setlocal breakindentopt=
|
||||||
|
setlocal bufhidden=
|
||||||
|
setlocal buflisted
|
||||||
|
setlocal buftype=
|
||||||
|
setlocal nocindent
|
||||||
|
setlocal cinkeys=0{,0},0),:,!^F,o,O,e
|
||||||
|
setlocal cinoptions=
|
||||||
|
setlocal cinwords=if,else,while,do,for,switch
|
||||||
|
setlocal colorcolumn=
|
||||||
|
setlocal comments=b:#,fb:-
|
||||||
|
setlocal commentstring=#\ %s
|
||||||
|
setlocal complete=.,w,b,u,t,i
|
||||||
|
setlocal concealcursor=
|
||||||
|
setlocal conceallevel=0
|
||||||
|
setlocal completefunc=
|
||||||
|
setlocal nocopyindent
|
||||||
|
setlocal cryptmethod=
|
||||||
|
setlocal nocursorbind
|
||||||
|
setlocal nocursorcolumn
|
||||||
|
setlocal nocursorline
|
||||||
|
setlocal define=
|
||||||
|
setlocal dictionary=
|
||||||
|
setlocal nodiff
|
||||||
|
setlocal equalprg=
|
||||||
|
setlocal errorformat=
|
||||||
|
setlocal expandtab
|
||||||
|
if &filetype != 'python'
|
||||||
|
setlocal filetype=python
|
||||||
|
endif
|
||||||
|
setlocal fixendofline
|
||||||
|
setlocal foldcolumn=0
|
||||||
|
setlocal foldenable
|
||||||
|
setlocal foldexpr=0
|
||||||
|
setlocal foldignore=#
|
||||||
|
setlocal foldlevel=0
|
||||||
|
setlocal foldmarker={{{,}}}
|
||||||
|
setlocal foldmethod=manual
|
||||||
|
setlocal foldminlines=1
|
||||||
|
setlocal foldnestmax=20
|
||||||
|
setlocal foldtext=foldtext()
|
||||||
|
setlocal formatexpr=
|
||||||
|
setlocal formatoptions=tcq
|
||||||
|
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
|
||||||
|
setlocal formatprg=
|
||||||
|
setlocal grepprg=
|
||||||
|
setlocal iminsert=0
|
||||||
|
setlocal imsearch=-1
|
||||||
|
setlocal include=^\\s*\\(from\\|import\\)
|
||||||
|
setlocal includeexpr=substitute(v:fname,'\\.','/','g')
|
||||||
|
setlocal indentexpr=GetPythonIndent(v:lnum)
|
||||||
|
setlocal indentkeys=0{,0},:,!^F,o,O,e,<:>,=elif,=except
|
||||||
|
setlocal noinfercase
|
||||||
|
setlocal iskeyword=@,48-57,_,192-255
|
||||||
|
setlocal keywordprg=
|
||||||
|
setlocal nolinebreak
|
||||||
|
setlocal nolisp
|
||||||
|
setlocal lispwords=
|
||||||
|
setlocal nolist
|
||||||
|
setlocal makeencoding=
|
||||||
|
setlocal makeprg=
|
||||||
|
setlocal matchpairs=(:),{:},[:]
|
||||||
|
setlocal nomodeline
|
||||||
|
setlocal modifiable
|
||||||
|
setlocal nrformats=bin,hex
|
||||||
|
setlocal nonumber
|
||||||
|
setlocal numberwidth=4
|
||||||
|
setlocal omnifunc=python3complete#Complete
|
||||||
|
setlocal path=
|
||||||
|
setlocal nopreserveindent
|
||||||
|
setlocal nopreviewwindow
|
||||||
|
setlocal quoteescape=\\
|
||||||
|
setlocal noreadonly
|
||||||
|
setlocal norelativenumber
|
||||||
|
setlocal norightleft
|
||||||
|
setlocal rightleftcmd=search
|
||||||
|
setlocal noscrollbind
|
||||||
|
setlocal shiftwidth=4
|
||||||
|
setlocal noshortname
|
||||||
|
setlocal signcolumn=auto
|
||||||
|
setlocal nosmartindent
|
||||||
|
setlocal softtabstop=4
|
||||||
|
setlocal nospell
|
||||||
|
setlocal spellcapcheck=[.?!]\\_[\\])'\"\ \ ]\\+
|
||||||
|
setlocal spellfile=
|
||||||
|
setlocal spelllang=en
|
||||||
|
setlocal statusline=
|
||||||
|
setlocal suffixesadd=.py
|
||||||
|
setlocal swapfile
|
||||||
|
setlocal synmaxcol=3000
|
||||||
|
if &syntax != 'python'
|
||||||
|
setlocal syntax=python
|
||||||
|
endif
|
||||||
|
setlocal tabstop=8
|
||||||
|
setlocal tagcase=
|
||||||
|
setlocal tags=
|
||||||
|
setlocal termkey=
|
||||||
|
setlocal termsize=
|
||||||
|
setlocal textwidth=0
|
||||||
|
setlocal thesaurus=
|
||||||
|
setlocal noundofile
|
||||||
|
setlocal undolevels=-123456
|
||||||
|
setlocal nowinfixheight
|
||||||
|
setlocal nowinfixwidth
|
||||||
|
setlocal wrap
|
||||||
|
setlocal wrapmargin=0
|
||||||
|
silent! normal! zE
|
||||||
|
let s:l = 5 - ((4 * winheight(0) + 51) / 102)
|
||||||
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
|
exe s:l
|
||||||
|
normal! zt
|
||||||
|
5
|
||||||
|
normal! 0
|
||||||
|
tabedit webhook.py
|
||||||
|
set splitbelow splitright
|
||||||
|
set nosplitbelow
|
||||||
|
set nosplitright
|
||||||
|
wincmd t
|
||||||
|
set winminheight=1 winheight=1 winminwidth=1 winwidth=1
|
||||||
|
argglobal
|
||||||
|
setlocal keymap=
|
||||||
|
setlocal noarabic
|
||||||
|
setlocal autoindent
|
||||||
|
setlocal backupcopy=
|
||||||
|
setlocal balloonexpr=
|
||||||
|
setlocal nobinary
|
||||||
|
setlocal nobreakindent
|
||||||
|
setlocal breakindentopt=
|
||||||
|
setlocal bufhidden=
|
||||||
|
setlocal buflisted
|
||||||
|
setlocal buftype=
|
||||||
|
setlocal nocindent
|
||||||
|
setlocal cinkeys=0{,0},0),:,!^F,o,O,e
|
||||||
|
setlocal cinoptions=
|
||||||
|
setlocal cinwords=if,else,while,do,for,switch
|
||||||
|
setlocal colorcolumn=
|
||||||
|
setlocal comments=b:#,fb:-
|
||||||
|
setlocal commentstring=#\ %s
|
||||||
|
setlocal complete=.,w,b,u,t,i
|
||||||
|
setlocal concealcursor=
|
||||||
|
setlocal conceallevel=0
|
||||||
|
setlocal completefunc=
|
||||||
|
setlocal nocopyindent
|
||||||
|
setlocal cryptmethod=
|
||||||
|
setlocal nocursorbind
|
||||||
|
setlocal nocursorcolumn
|
||||||
|
setlocal nocursorline
|
||||||
|
setlocal define=
|
||||||
|
setlocal dictionary=
|
||||||
|
setlocal nodiff
|
||||||
|
setlocal equalprg=
|
||||||
|
setlocal errorformat=
|
||||||
|
setlocal expandtab
|
||||||
|
if &filetype != 'python'
|
||||||
|
setlocal filetype=python
|
||||||
|
endif
|
||||||
|
setlocal fixendofline
|
||||||
|
setlocal foldcolumn=0
|
||||||
|
setlocal foldenable
|
||||||
|
setlocal foldexpr=0
|
||||||
|
setlocal foldignore=#
|
||||||
|
setlocal foldlevel=0
|
||||||
|
setlocal foldmarker={{{,}}}
|
||||||
|
setlocal foldmethod=manual
|
||||||
|
setlocal foldminlines=1
|
||||||
|
setlocal foldnestmax=20
|
||||||
|
setlocal foldtext=foldtext()
|
||||||
|
setlocal formatexpr=
|
||||||
|
setlocal formatoptions=tcq
|
||||||
|
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
|
||||||
|
setlocal formatprg=
|
||||||
|
setlocal grepprg=
|
||||||
|
setlocal iminsert=0
|
||||||
|
setlocal imsearch=-1
|
||||||
|
setlocal include=^\\s*\\(from\\|import\\)
|
||||||
|
setlocal includeexpr=substitute(v:fname,'\\.','/','g')
|
||||||
|
setlocal indentexpr=GetPythonIndent(v:lnum)
|
||||||
|
setlocal indentkeys=0{,0},:,!^F,o,O,e,<:>,=elif,=except
|
||||||
|
setlocal noinfercase
|
||||||
|
setlocal iskeyword=@,48-57,_,192-255
|
||||||
|
setlocal keywordprg=
|
||||||
|
setlocal nolinebreak
|
||||||
|
setlocal nolisp
|
||||||
|
setlocal lispwords=
|
||||||
|
setlocal nolist
|
||||||
|
setlocal makeencoding=
|
||||||
|
setlocal makeprg=
|
||||||
|
setlocal matchpairs=(:),{:},[:]
|
||||||
|
setlocal nomodeline
|
||||||
|
setlocal modifiable
|
||||||
|
setlocal nrformats=bin,hex
|
||||||
|
setlocal nonumber
|
||||||
|
setlocal numberwidth=4
|
||||||
|
setlocal omnifunc=python3complete#Complete
|
||||||
|
setlocal path=
|
||||||
|
setlocal nopreserveindent
|
||||||
|
setlocal nopreviewwindow
|
||||||
|
setlocal quoteescape=\\
|
||||||
|
setlocal noreadonly
|
||||||
|
setlocal norelativenumber
|
||||||
|
setlocal norightleft
|
||||||
|
setlocal rightleftcmd=search
|
||||||
|
setlocal noscrollbind
|
||||||
|
setlocal shiftwidth=4
|
||||||
|
setlocal noshortname
|
||||||
|
setlocal signcolumn=auto
|
||||||
|
setlocal nosmartindent
|
||||||
|
setlocal softtabstop=4
|
||||||
|
setlocal nospell
|
||||||
|
setlocal spellcapcheck=[.?!]\\_[\\])'\"\ \ ]\\+
|
||||||
|
setlocal spellfile=
|
||||||
|
setlocal spelllang=en
|
||||||
|
setlocal statusline=
|
||||||
|
setlocal suffixesadd=.py
|
||||||
|
setlocal swapfile
|
||||||
|
setlocal synmaxcol=3000
|
||||||
|
if &syntax != 'python'
|
||||||
|
setlocal syntax=python
|
||||||
|
endif
|
||||||
|
setlocal tabstop=8
|
||||||
|
setlocal tagcase=
|
||||||
|
setlocal tags=
|
||||||
|
setlocal termkey=
|
||||||
|
setlocal termsize=
|
||||||
|
setlocal textwidth=0
|
||||||
|
setlocal thesaurus=
|
||||||
|
setlocal noundofile
|
||||||
|
setlocal undolevels=-123456
|
||||||
|
setlocal nowinfixheight
|
||||||
|
setlocal nowinfixwidth
|
||||||
|
setlocal wrap
|
||||||
|
setlocal wrapmargin=0
|
||||||
|
silent! normal! zE
|
||||||
|
let s:l = 1 - ((0 * winheight(0) + 51) / 102)
|
||||||
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
|
exe s:l
|
||||||
|
normal! zt
|
||||||
|
1
|
||||||
|
normal! 0
|
||||||
|
tabedit worker.py
|
||||||
|
set splitbelow splitright
|
||||||
|
set nosplitbelow
|
||||||
|
set nosplitright
|
||||||
|
wincmd t
|
||||||
|
set winminheight=1 winheight=1 winminwidth=1 winwidth=1
|
||||||
|
argglobal
|
||||||
|
setlocal keymap=
|
||||||
|
setlocal noarabic
|
||||||
|
setlocal autoindent
|
||||||
|
setlocal backupcopy=
|
||||||
|
setlocal balloonexpr=
|
||||||
|
setlocal nobinary
|
||||||
|
setlocal nobreakindent
|
||||||
|
setlocal breakindentopt=
|
||||||
|
setlocal bufhidden=
|
||||||
|
setlocal buflisted
|
||||||
|
setlocal buftype=
|
||||||
|
setlocal nocindent
|
||||||
|
setlocal cinkeys=0{,0},0),:,!^F,o,O,e
|
||||||
|
setlocal cinoptions=
|
||||||
|
setlocal cinwords=if,else,while,do,for,switch
|
||||||
|
setlocal colorcolumn=
|
||||||
|
setlocal comments=b:#,fb:-
|
||||||
|
setlocal commentstring=#\ %s
|
||||||
|
setlocal complete=.,w,b,u,t,i
|
||||||
|
setlocal concealcursor=
|
||||||
|
setlocal conceallevel=0
|
||||||
|
setlocal completefunc=
|
||||||
|
setlocal nocopyindent
|
||||||
|
setlocal cryptmethod=
|
||||||
|
setlocal nocursorbind
|
||||||
|
setlocal nocursorcolumn
|
||||||
|
setlocal nocursorline
|
||||||
|
setlocal define=
|
||||||
|
setlocal dictionary=
|
||||||
|
setlocal nodiff
|
||||||
|
setlocal equalprg=
|
||||||
|
setlocal errorformat=
|
||||||
|
setlocal expandtab
|
||||||
|
if &filetype != 'python'
|
||||||
|
setlocal filetype=python
|
||||||
|
endif
|
||||||
|
setlocal fixendofline
|
||||||
|
setlocal foldcolumn=0
|
||||||
|
setlocal foldenable
|
||||||
|
setlocal foldexpr=0
|
||||||
|
setlocal foldignore=#
|
||||||
|
setlocal foldlevel=0
|
||||||
|
setlocal foldmarker={{{,}}}
|
||||||
|
setlocal foldmethod=manual
|
||||||
|
setlocal foldminlines=1
|
||||||
|
setlocal foldnestmax=20
|
||||||
|
setlocal foldtext=foldtext()
|
||||||
|
setlocal formatexpr=
|
||||||
|
setlocal formatoptions=tcq
|
||||||
|
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
|
||||||
|
setlocal formatprg=
|
||||||
|
setlocal grepprg=
|
||||||
|
setlocal iminsert=0
|
||||||
|
setlocal imsearch=-1
|
||||||
|
setlocal include=^\\s*\\(from\\|import\\)
|
||||||
|
setlocal includeexpr=substitute(v:fname,'\\.','/','g')
|
||||||
|
setlocal indentexpr=GetPythonIndent(v:lnum)
|
||||||
|
setlocal indentkeys=0{,0},:,!^F,o,O,e,<:>,=elif,=except
|
||||||
|
setlocal noinfercase
|
||||||
|
setlocal iskeyword=@,48-57,_,192-255
|
||||||
|
setlocal keywordprg=
|
||||||
|
setlocal nolinebreak
|
||||||
|
setlocal nolisp
|
||||||
|
setlocal lispwords=
|
||||||
|
setlocal nolist
|
||||||
|
setlocal makeencoding=
|
||||||
|
setlocal makeprg=
|
||||||
|
setlocal matchpairs=(:),{:},[:]
|
||||||
|
setlocal nomodeline
|
||||||
|
setlocal modifiable
|
||||||
|
setlocal nrformats=bin,hex
|
||||||
|
setlocal nonumber
|
||||||
|
setlocal numberwidth=4
|
||||||
|
setlocal omnifunc=python3complete#Complete
|
||||||
|
setlocal path=
|
||||||
|
setlocal nopreserveindent
|
||||||
|
setlocal nopreviewwindow
|
||||||
|
setlocal quoteescape=\\
|
||||||
|
setlocal noreadonly
|
||||||
|
setlocal norelativenumber
|
||||||
|
setlocal norightleft
|
||||||
|
setlocal rightleftcmd=search
|
||||||
|
setlocal noscrollbind
|
||||||
|
setlocal shiftwidth=4
|
||||||
|
setlocal noshortname
|
||||||
|
setlocal signcolumn=auto
|
||||||
|
setlocal nosmartindent
|
||||||
|
setlocal softtabstop=4
|
||||||
|
setlocal nospell
|
||||||
|
setlocal spellcapcheck=[.?!]\\_[\\])'\"\ \ ]\\+
|
||||||
|
setlocal spellfile=
|
||||||
|
setlocal spelllang=en
|
||||||
|
setlocal statusline=
|
||||||
|
setlocal suffixesadd=.py
|
||||||
|
setlocal swapfile
|
||||||
|
setlocal synmaxcol=3000
|
||||||
|
if &syntax != 'python'
|
||||||
|
setlocal syntax=python
|
||||||
|
endif
|
||||||
|
setlocal tabstop=8
|
||||||
|
setlocal tagcase=
|
||||||
|
setlocal tags=
|
||||||
|
setlocal termkey=
|
||||||
|
setlocal termsize=
|
||||||
|
setlocal textwidth=0
|
||||||
|
setlocal thesaurus=
|
||||||
|
setlocal noundofile
|
||||||
|
setlocal undolevels=-123456
|
||||||
|
setlocal nowinfixheight
|
||||||
|
setlocal nowinfixwidth
|
||||||
|
setlocal wrap
|
||||||
|
setlocal wrapmargin=0
|
||||||
|
silent! normal! zE
|
||||||
|
let s:l = 31 - ((30 * winheight(0) + 51) / 102)
|
||||||
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
|
exe s:l
|
||||||
|
normal! zt
|
||||||
|
31
|
||||||
|
normal! 09|
|
||||||
|
tabedit assets/settings.ini
|
||||||
|
set splitbelow splitright
|
||||||
|
set nosplitbelow
|
||||||
|
set nosplitright
|
||||||
|
wincmd t
|
||||||
|
set winminheight=1 winheight=1 winminwidth=1 winwidth=1
|
||||||
|
argglobal
|
||||||
|
setlocal keymap=
|
||||||
|
setlocal noarabic
|
||||||
|
setlocal noautoindent
|
||||||
|
setlocal backupcopy=
|
||||||
|
setlocal balloonexpr=
|
||||||
|
setlocal nobinary
|
||||||
|
setlocal nobreakindent
|
||||||
|
setlocal breakindentopt=
|
||||||
|
setlocal bufhidden=
|
||||||
|
setlocal buflisted
|
||||||
|
setlocal buftype=
|
||||||
|
setlocal nocindent
|
||||||
|
setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
|
||||||
|
setlocal cinoptions=
|
||||||
|
setlocal cinwords=if,else,while,do,for,switch
|
||||||
|
setlocal colorcolumn=
|
||||||
|
setlocal comments=:;
|
||||||
|
setlocal commentstring=;\ %s
|
||||||
|
setlocal complete=.,w,b,u,t,i
|
||||||
|
setlocal concealcursor=
|
||||||
|
setlocal conceallevel=0
|
||||||
|
setlocal completefunc=
|
||||||
|
setlocal nocopyindent
|
||||||
|
setlocal cryptmethod=
|
||||||
|
setlocal nocursorbind
|
||||||
|
setlocal nocursorcolumn
|
||||||
|
setlocal nocursorline
|
||||||
|
setlocal define=
|
||||||
|
setlocal dictionary=
|
||||||
|
setlocal nodiff
|
||||||
|
setlocal equalprg=
|
||||||
|
setlocal errorformat=
|
||||||
|
setlocal noexpandtab
|
||||||
|
if &filetype != 'dosini'
|
||||||
|
setlocal filetype=dosini
|
||||||
|
endif
|
||||||
|
setlocal fixendofline
|
||||||
|
setlocal foldcolumn=0
|
||||||
|
setlocal foldenable
|
||||||
|
setlocal foldexpr=0
|
||||||
|
setlocal foldignore=#
|
||||||
|
setlocal foldlevel=0
|
||||||
|
setlocal foldmarker={{{,}}}
|
||||||
|
setlocal foldmethod=manual
|
||||||
|
setlocal foldminlines=1
|
||||||
|
setlocal foldnestmax=20
|
||||||
|
setlocal foldtext=foldtext()
|
||||||
|
setlocal formatexpr=
|
||||||
|
setlocal formatoptions=croql
|
||||||
|
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
|
||||||
|
setlocal formatprg=
|
||||||
|
setlocal grepprg=
|
||||||
|
setlocal iminsert=0
|
||||||
|
setlocal imsearch=-1
|
||||||
|
setlocal include=
|
||||||
|
setlocal includeexpr=
|
||||||
|
setlocal indentexpr=
|
||||||
|
setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
|
||||||
|
setlocal noinfercase
|
||||||
|
setlocal iskeyword=@,48-57,_,192-255
|
||||||
|
setlocal keywordprg=
|
||||||
|
setlocal nolinebreak
|
||||||
|
setlocal nolisp
|
||||||
|
setlocal lispwords=
|
||||||
|
setlocal nolist
|
||||||
|
setlocal makeencoding=
|
||||||
|
setlocal makeprg=
|
||||||
|
setlocal matchpairs=(:),{:},[:]
|
||||||
|
setlocal nomodeline
|
||||||
|
setlocal modifiable
|
||||||
|
setlocal nrformats=bin,hex
|
||||||
|
setlocal nonumber
|
||||||
|
setlocal numberwidth=4
|
||||||
|
setlocal omnifunc=
|
||||||
|
setlocal path=
|
||||||
|
setlocal nopreserveindent
|
||||||
|
setlocal nopreviewwindow
|
||||||
|
setlocal quoteescape=\\
|
||||||
|
setlocal noreadonly
|
||||||
|
setlocal norelativenumber
|
||||||
|
setlocal norightleft
|
||||||
|
setlocal rightleftcmd=search
|
||||||
|
setlocal noscrollbind
|
||||||
|
setlocal shiftwidth=8
|
||||||
|
setlocal noshortname
|
||||||
|
setlocal signcolumn=auto
|
||||||
|
setlocal nosmartindent
|
||||||
|
setlocal softtabstop=0
|
||||||
|
setlocal nospell
|
||||||
|
setlocal spellcapcheck=[.?!]\\_[\\])'\"\ \ ]\\+
|
||||||
|
setlocal spellfile=
|
||||||
|
setlocal spelllang=en
|
||||||
|
setlocal statusline=
|
||||||
|
setlocal suffixesadd=
|
||||||
|
setlocal swapfile
|
||||||
|
setlocal synmaxcol=3000
|
||||||
|
if &syntax != 'dosini'
|
||||||
|
setlocal syntax=dosini
|
||||||
|
endif
|
||||||
|
setlocal tabstop=8
|
||||||
|
setlocal tagcase=
|
||||||
|
setlocal tags=
|
||||||
|
setlocal termkey=
|
||||||
|
setlocal termsize=
|
||||||
|
setlocal textwidth=0
|
||||||
|
setlocal thesaurus=
|
||||||
|
setlocal noundofile
|
||||||
|
setlocal undolevels=-123456
|
||||||
|
setlocal nowinfixheight
|
||||||
|
setlocal nowinfixwidth
|
||||||
|
setlocal wrap
|
||||||
|
setlocal wrapmargin=0
|
||||||
|
silent! normal! zE
|
||||||
|
let s:l = 3 - ((2 * winheight(0) + 51) / 102)
|
||||||
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
|
exe s:l
|
||||||
|
normal! zt
|
||||||
|
3
|
||||||
|
normal! 040|
|
||||||
|
tabedit main.py
|
||||||
|
set splitbelow splitright
|
||||||
|
set nosplitbelow
|
||||||
|
set nosplitright
|
||||||
|
wincmd t
|
||||||
|
set winminheight=1 winheight=1 winminwidth=1 winwidth=1
|
||||||
|
argglobal
|
||||||
|
setlocal keymap=
|
||||||
|
setlocal noarabic
|
||||||
|
setlocal autoindent
|
||||||
|
setlocal backupcopy=
|
||||||
|
setlocal balloonexpr=
|
||||||
|
setlocal nobinary
|
||||||
|
setlocal nobreakindent
|
||||||
|
setlocal breakindentopt=
|
||||||
|
setlocal bufhidden=
|
||||||
|
setlocal buflisted
|
||||||
|
setlocal buftype=
|
||||||
|
setlocal nocindent
|
||||||
|
setlocal cinkeys=0{,0},0),:,!^F,o,O,e
|
||||||
|
setlocal cinoptions=
|
||||||
|
setlocal cinwords=if,else,while,do,for,switch
|
||||||
|
setlocal colorcolumn=
|
||||||
|
setlocal comments=b:#,fb:-
|
||||||
|
setlocal commentstring=#\ %s
|
||||||
|
setlocal complete=.,w,b,u,t,i
|
||||||
|
setlocal concealcursor=
|
||||||
|
setlocal conceallevel=0
|
||||||
|
setlocal completefunc=
|
||||||
|
setlocal nocopyindent
|
||||||
|
setlocal cryptmethod=
|
||||||
|
setlocal nocursorbind
|
||||||
|
setlocal nocursorcolumn
|
||||||
|
setlocal nocursorline
|
||||||
|
setlocal define=
|
||||||
|
setlocal dictionary=
|
||||||
|
setlocal nodiff
|
||||||
|
setlocal equalprg=
|
||||||
|
setlocal errorformat=
|
||||||
|
setlocal expandtab
|
||||||
|
if &filetype != 'python'
|
||||||
|
setlocal filetype=python
|
||||||
|
endif
|
||||||
|
setlocal fixendofline
|
||||||
|
setlocal foldcolumn=0
|
||||||
|
setlocal foldenable
|
||||||
|
setlocal foldexpr=0
|
||||||
|
setlocal foldignore=#
|
||||||
|
setlocal foldlevel=0
|
||||||
|
setlocal foldmarker={{{,}}}
|
||||||
|
setlocal foldmethod=manual
|
||||||
|
setlocal foldminlines=1
|
||||||
|
setlocal foldnestmax=20
|
||||||
|
setlocal foldtext=foldtext()
|
||||||
|
setlocal formatexpr=
|
||||||
|
setlocal formatoptions=tcq
|
||||||
|
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
|
||||||
|
setlocal formatprg=
|
||||||
|
setlocal grepprg=
|
||||||
|
setlocal iminsert=0
|
||||||
|
setlocal imsearch=-1
|
||||||
|
setlocal include=^\\s*\\(from\\|import\\)
|
||||||
|
setlocal includeexpr=substitute(v:fname,'\\.','/','g')
|
||||||
|
setlocal indentexpr=GetPythonIndent(v:lnum)
|
||||||
|
setlocal indentkeys=0{,0},:,!^F,o,O,e,<:>,=elif,=except
|
||||||
|
setlocal noinfercase
|
||||||
|
setlocal iskeyword=@,48-57,_,192-255
|
||||||
|
setlocal keywordprg=
|
||||||
|
setlocal nolinebreak
|
||||||
|
setlocal nolisp
|
||||||
|
setlocal lispwords=
|
||||||
|
setlocal nolist
|
||||||
|
setlocal makeencoding=
|
||||||
|
setlocal makeprg=
|
||||||
|
setlocal matchpairs=(:),{:},[:]
|
||||||
|
setlocal nomodeline
|
||||||
|
setlocal modifiable
|
||||||
|
setlocal nrformats=bin,hex
|
||||||
|
setlocal nonumber
|
||||||
|
setlocal numberwidth=4
|
||||||
|
setlocal omnifunc=python3complete#Complete
|
||||||
|
setlocal path=
|
||||||
|
setlocal nopreserveindent
|
||||||
|
setlocal nopreviewwindow
|
||||||
|
setlocal quoteescape=\\
|
||||||
|
setlocal readonly
|
||||||
|
setlocal norelativenumber
|
||||||
|
setlocal norightleft
|
||||||
|
setlocal rightleftcmd=search
|
||||||
|
setlocal noscrollbind
|
||||||
|
setlocal shiftwidth=4
|
||||||
|
setlocal noshortname
|
||||||
|
setlocal signcolumn=auto
|
||||||
|
setlocal nosmartindent
|
||||||
|
setlocal softtabstop=4
|
||||||
|
setlocal nospell
|
||||||
|
setlocal spellcapcheck=[.?!]\\_[\\])'\"\ \ ]\\+
|
||||||
|
setlocal spellfile=
|
||||||
|
setlocal spelllang=en
|
||||||
|
setlocal statusline=
|
||||||
|
setlocal suffixesadd=.py
|
||||||
|
setlocal swapfile
|
||||||
|
setlocal synmaxcol=3000
|
||||||
|
if &syntax != 'python'
|
||||||
|
setlocal syntax=python
|
||||||
|
endif
|
||||||
|
setlocal tabstop=8
|
||||||
|
setlocal tagcase=
|
||||||
|
setlocal tags=
|
||||||
|
setlocal termkey=
|
||||||
|
setlocal termsize=
|
||||||
|
setlocal textwidth=0
|
||||||
|
setlocal thesaurus=
|
||||||
|
setlocal noundofile
|
||||||
|
setlocal undolevels=-123456
|
||||||
|
setlocal nowinfixheight
|
||||||
|
setlocal nowinfixwidth
|
||||||
|
setlocal wrap
|
||||||
|
setlocal wrapmargin=0
|
||||||
|
silent! normal! zE
|
||||||
|
let s:l = 1 - ((0 * winheight(0) + 51) / 102)
|
||||||
|
if s:l < 1 | let s:l = 1 | endif
|
||||||
|
exe s:l
|
||||||
|
normal! zt
|
||||||
|
1
|
||||||
|
normal! 0
|
||||||
|
tabnext 2
|
||||||
|
set stal=1
|
||||||
|
if exists('s:wipebuf')
|
||||||
|
silent exe 'bwipe ' . s:wipebuf
|
||||||
|
endif
|
||||||
|
unlet! s:wipebuf
|
||||||
|
set winheight=1 winwidth=20 shortmess=filnxtToO
|
||||||
|
set winminheight=1 winminwidth=1
|
||||||
|
let s:sx = expand("<sfile>:p:r")."x.vim"
|
||||||
|
if file_readable(s:sx)
|
||||||
|
exe "source " . fnameescape(s:sx)
|
||||||
|
endif
|
||||||
|
let &so = s:so_save | let &siso = s:siso_save
|
||||||
|
doautoall SessionLoadPost
|
||||||
|
unlet SessionLoad
|
||||||
|
" vim: set ft=vim :
|
30
webhook.py
30
webhook.py
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from http.server import HTTPServer,SimpleHTTPRequestHandler,CGIHTTPRequestHandler
|
from http.server import HTTPServer, SimpleHTTPRequestHandler, CGIHTTPRequestHandler
|
||||||
from socketserver import BaseServer
|
from socketserver import BaseServer
|
||||||
import ssl
|
import ssl
|
||||||
import json
|
import json
|
||||||
@ -10,11 +10,12 @@ import settings
|
|||||||
# fuckin dirty hack. idk the best way to inherit return func into
|
# fuckin dirty hack. idk the best way to inherit return func into
|
||||||
# RequestHandler class
|
# RequestHandler class
|
||||||
|
|
||||||
|
|
||||||
class RequestHandler(SimpleHTTPRequestHandler):
|
class RequestHandler(SimpleHTTPRequestHandler):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
request,
|
request,
|
||||||
client_address,
|
client_address,
|
||||||
server):
|
server):
|
||||||
self.worker = settings.worker
|
self.worker = settings.worker
|
||||||
super(RequestHandler, self).__init__(
|
super(RequestHandler, self).__init__(
|
||||||
request=request,
|
request=request,
|
||||||
@ -36,26 +37,27 @@ class RequestHandler(SimpleHTTPRequestHandler):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class WebHook:
|
class WebHook:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
certfile,
|
certfile,
|
||||||
keyfile,
|
keyfile,
|
||||||
address = '0.0.0.0',
|
address=settings.parser.get('bot', 'bind_address'),
|
||||||
port=8443,
|
port=8443,
|
||||||
RequestHandler=RequestHandler):
|
RequestHandler=RequestHandler):
|
||||||
|
|
||||||
self.httpd = HTTPServer((address, port), RequestHandler)
|
self.httpd = HTTPServer((address, port), RequestHandler)
|
||||||
self.httpd.socket = ssl.wrap_socket (self.httpd.socket,
|
self.httpd.socket = ssl.wrap_socket(self.httpd.socket,
|
||||||
certfile=certfile,
|
certfile=certfile,
|
||||||
keyfile=keyfile,
|
keyfile=keyfile,
|
||||||
server_side=True)
|
server_side=True)
|
||||||
|
|
||||||
def serve(self):
|
def serve(self):
|
||||||
try:
|
try:
|
||||||
self.httpd.serve_forever()
|
self.httpd.serve_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
print("ERROR: %s" % e)
|
||||||
finally:
|
finally:
|
||||||
# Clean-up server (close socket, etc.)
|
# Clean-up server (close socket, etc.)
|
||||||
self.httpd.server_close()
|
self.httpd.server_close()
|
||||||
|
407
worker.py
407
worker.py
@ -1,102 +1,316 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from string import punctuation
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from database import DataBase
|
|
||||||
import os
|
import os
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from urllib.parse import urlencode
|
import requests
|
||||||
|
import json
|
||||||
import settings
|
import settings
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
|
import threading
|
||||||
|
import random
|
||||||
|
|
||||||
|
from string import punctuation
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
from database import DataBase
|
||||||
|
from markov.simple import get
|
||||||
|
|
||||||
|
from pygments import highlight
|
||||||
|
from pygments.lexers import PythonLexer
|
||||||
|
from pygments.lexers import guess_lexer, get_lexer_by_name
|
||||||
|
from pygments.styles import get_style_by_name
|
||||||
|
from pygments.formatters import ImageFormatter
|
||||||
|
|
||||||
|
|
||||||
class MessageWorker:
|
class MessageWorker:
|
||||||
def __init__(self, db, stop_words = 'assets/stop-word.ru'):
|
def __init__(self, db, stop_words='assets/stop-word.ru', settings=settings):
|
||||||
self.stop_words = stop_words
|
self.stop_words = stop_words
|
||||||
self.db = db
|
self.db = db
|
||||||
|
self.telegram_key = settings.parser.get('bot', 'telegram_key')
|
||||||
|
self.telegram_api = settings.parser.get('bot', 'telegram_api')
|
||||||
|
self.me = self.getMe()
|
||||||
|
self.cron_timer()
|
||||||
|
print("My name is %s" % self.me['result']['username'])
|
||||||
|
|
||||||
|
def getMe(self):
|
||||||
|
url = self.telegram_api + 'bot' + self.telegram_key + '/getMe'
|
||||||
|
print(url)
|
||||||
|
urllib.request.Request(url)
|
||||||
|
request = urllib.request.Request(url)
|
||||||
|
raw = urllib.request.urlopen(request).read().decode()
|
||||||
|
return json.loads(raw)
|
||||||
|
|
||||||
|
def isTime(self, string):
|
||||||
|
try:
|
||||||
|
time.strptime(string, '%H%M')
|
||||||
|
return string
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
if (int(string[1:]) > 0) and (string[0] == '+') and (len(string[1:]) < 4):
|
||||||
|
return string
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def colorize(self, code):
|
||||||
|
code_tag = code[code.rfind('#') + 1:]
|
||||||
|
try:
|
||||||
|
lexer = get_lexer_by_name(code_tag)
|
||||||
|
code = code[:code.rfind('#')]
|
||||||
|
except:
|
||||||
|
lexer = guess_lexer(code)
|
||||||
|
print("Lexer is defined as %s" % lexer)
|
||||||
|
if lexer.name == 'Text only':
|
||||||
|
lexer = get_lexer_by_name('python')
|
||||||
|
print(highlight(code, lexer, ImageFormatter(
|
||||||
|
font_size=16,
|
||||||
|
line_number_bg="#242e0c",
|
||||||
|
line_number_fg="#faddf2",
|
||||||
|
line_number_bold=True,
|
||||||
|
font_name='DejaVuSansMono',
|
||||||
|
style=get_style_by_name('monokai')), outfile="code.png"))
|
||||||
|
|
||||||
|
|
||||||
def handleUpdate(self, msg):
|
def handleUpdate(self, msg):
|
||||||
try:
|
try:
|
||||||
if msg['message']['text'] == '/scheme':
|
try:
|
||||||
conf_id = msg['message']['chat']['id']
|
input_message = msg['message']['text']
|
||||||
user_id = msg['message']['from']['id']
|
except KeyError as excp:
|
||||||
chat_title = msg['message']['chat']['title']
|
print(f"KeyError: {excp}")
|
||||||
self.db.add_conf(conf_id, chat_title)
|
|
||||||
self.send(id=conf_id, msg='```\n' + self.db.scheme + '\n```')
|
|
||||||
return True
|
return True
|
||||||
|
if input_message == '/help':
|
||||||
if msg['message']['text'] == '/stat':
|
|
||||||
conf_id = msg['message']['chat']['id']
|
conf_id = msg['message']['chat']['id']
|
||||||
user_id = msg['message']['from']['id']
|
user_id = msg['message']['from']['id']
|
||||||
chat_title = msg['message']['chat']['title']
|
if msg['message']['chat']['type'] == 'private':
|
||||||
|
chat_title = conf_id
|
||||||
|
else:
|
||||||
|
chat_title = msg['message']['chat']['title']
|
||||||
self.db.add_conf(conf_id, chat_title)
|
self.db.add_conf(conf_id, chat_title)
|
||||||
|
msg = """
|
||||||
message = """Here is your top:\n"""
|
Commands:
|
||||||
top = self.db.get_top(
|
@here - call all conf users
|
||||||
user_id=user_id,
|
/stat - show user stat
|
||||||
conf_id=conf_id
|
/scheme - print sql schema
|
||||||
)
|
/reset - reset user stat
|
||||||
for word in top:
|
/sql - execute sql
|
||||||
message += '*%s*: %s\n' % (word[1], word[0])
|
/alert - set alert
|
||||||
self.send(id=conf_id, msg=message)
|
/code - highlight code snippet
|
||||||
return True
|
"""
|
||||||
|
self.send(id=conf_id, msg=msg)
|
||||||
if msg['message']['text'] == '/reset':
|
if ('@here' in input_message) or (' @'+self.me['result']['username'] in input_message):
|
||||||
|
# if str(msg['message']['chat']['id']) != "-1001233797421":
|
||||||
|
# print("@here isn't available for '%s' (%s)" % (msg['message']['chat']['title'], msg['message']['chat']['id']))
|
||||||
|
# return
|
||||||
conf_id = msg['message']['chat']['id']
|
conf_id = msg['message']['chat']['id']
|
||||||
user_id = msg['message']['from']['id']
|
user_id = msg['message']['from']['id']
|
||||||
chat_title = msg['message']['chat']['title']
|
if msg['message']['chat']['type'] == 'private':
|
||||||
|
chat_title = conf_id
|
||||||
|
else:
|
||||||
|
chat_title = msg['message']['chat']['title']
|
||||||
self.db.add_conf(conf_id, chat_title)
|
self.db.add_conf(conf_id, chat_title)
|
||||||
|
if msg['message']['text'] != '@here':
|
||||||
|
message = msg['message']['text'].replace('@here', '\n').replace(' @'+self.me['result']['username'], '\n')
|
||||||
|
else:
|
||||||
|
message = """I summon you!\n"""
|
||||||
|
|
||||||
message = """Your stat has been resetted."""
|
|
||||||
self.db.reset(
|
|
||||||
conf_id=conf_id,
|
|
||||||
user_id=user_id)
|
|
||||||
return True
|
|
||||||
|
|
||||||
if msg['message']['text'][:4] == '/sql':
|
|
||||||
conf_id = msg['message']['chat']['id']
|
|
||||||
user_id = msg['message']['from']['id']
|
|
||||||
chat_title = msg['message']['chat']['title']
|
|
||||||
self.db.add_conf(conf_id, chat_title)
|
|
||||||
sql = msg['message']['text'][5:]
|
|
||||||
|
|
||||||
res = self.db.command(sql)
|
|
||||||
if 'syntax' in str(res) \
|
|
||||||
or 'ambiguous' in str(res):
|
|
||||||
self.send(id=conf_id, msg=str(res))
|
|
||||||
return False
|
|
||||||
try:
|
|
||||||
msg = '```\n'
|
|
||||||
for z in res:
|
|
||||||
for i in z:
|
|
||||||
msg = msg + str(i) + '\t'
|
|
||||||
msg = msg + '\n'
|
|
||||||
except:
|
|
||||||
msg = res
|
|
||||||
self.send(id=conf_id, msg=msg + ' ```')
|
|
||||||
return True
|
|
||||||
|
|
||||||
if msg['message']['text'][:5] == '@here' or \
|
|
||||||
msg['message']['text'][5:] == '@here':
|
|
||||||
conf_id = msg['message']['chat']['id']
|
|
||||||
user_id = msg['message']['from']['id']
|
|
||||||
chat_title = msg['message']['chat']['title']
|
|
||||||
self.db.add_conf(conf_id, chat_title)
|
|
||||||
|
|
||||||
message = """I summon you!\n"""
|
|
||||||
users = self.db.here(
|
users = self.db.here(
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
conf_id=conf_id
|
conf_id=conf_id
|
||||||
)
|
)
|
||||||
for user in users:
|
for user in users:
|
||||||
message += '@%s ' % (user[0])
|
message += ' [%s](tg://user?id=%s)' % (user[2], user[1])
|
||||||
self.send(id=conf_id, msg=message)
|
self.send(id=conf_id, msg=message)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
input_message = msg['message']['text'].replace(
|
||||||
|
'@' + self.me['result']['username'], '')
|
||||||
except:
|
except:
|
||||||
return False
|
input_message = msg['message']['text']
|
||||||
|
# if str(msg['message']['chat']['id']) == "-1001233797421":
|
||||||
|
# if random.randint(0,300) == 1:
|
||||||
|
# conf_id = msg['message']['chat']['id']
|
||||||
|
# user_id = msg['message']['from']['id']
|
||||||
|
# if msg['message']['chat']['type'] == 'private':
|
||||||
|
# chat_title = conf_id
|
||||||
|
# else:
|
||||||
|
# chat_title = msg['message']['chat']['title']
|
||||||
|
# self.db.add_conf(conf_id, chat_title)
|
||||||
|
# word_aya = self.db.get_random_word(count=1, like="%ая")
|
||||||
|
# word_da = self.db.get_random_word(count=1, like="%да")
|
||||||
|
# msg = "Ты %s %s." % (word_aya[0][0], word_da[0][0])
|
||||||
|
# self.send(id=conf_id, msg=msg)
|
||||||
|
# if (input_message[0] == 'я') or (input_message[0] == 'Я'):
|
||||||
|
# if len(input_message) > 3:
|
||||||
|
# conf_id = msg['message']['chat']['id']
|
||||||
|
# user_id = msg['message']['from']['id']
|
||||||
|
# if msg['message']['chat']['type'] == 'private':
|
||||||
|
# chat_title = conf_id
|
||||||
|
# else:
|
||||||
|
# chat_title = msg['message']['chat']['title']
|
||||||
|
# self.db.add_conf(conf_id, chat_title)
|
||||||
|
# answers = ['И чо бля?','Да и похуй.','Ну и хуй с тобой.','Нет я.']
|
||||||
|
# if random.randint(0,100) > 80:
|
||||||
|
# msg = answers[random.randint(0,len(answers)-1)]
|
||||||
|
# self.send(id=conf_id, msg=msg)
|
||||||
|
# if (input_message[0:1] == 'Ты') or (input_message[0:1] == 'ты'):
|
||||||
|
# if len(input_message) > 5:
|
||||||
|
# conf_id = msg['message']['chat']['id']
|
||||||
|
# user_id = msg['message']['from']['id']
|
||||||
|
# if msg['message']['chat']['type'] == 'private':
|
||||||
|
# chat_title = conf_id
|
||||||
|
# else:
|
||||||
|
# chat_title = msg['message']['chat']['title']
|
||||||
|
# self.db.add_conf(conf_id, chat_title)
|
||||||
|
# answers = ['Двачую.','Да.', 'А я покакал.', "Винда лучше."]
|
||||||
|
# if random.randint(0,100) > 70:
|
||||||
|
# msg = answers[random.randint(0,len(answers)-1)]
|
||||||
|
# self.send(id=conf_id, msg=msg)
|
||||||
|
if input_message == '/scheme':
|
||||||
|
conf_id = msg['message']['chat']['id']
|
||||||
|
user_id = msg['message']['from']['id']
|
||||||
|
if msg['message']['chat']['type'] == 'private':
|
||||||
|
chat_title = conf_id
|
||||||
|
else:
|
||||||
|
chat_title = msg['message']['chat']['title']
|
||||||
|
self.db.add_conf(conf_id, chat_title)
|
||||||
|
self.send(id=conf_id, msg='```\n' + self.db.scheme + '\n```')
|
||||||
|
return True
|
||||||
|
|
||||||
|
if input_message[:7] == '/markov':
|
||||||
|
conf_id = msg['message']['chat']['id']
|
||||||
|
user_id = msg['message']['from']['id']
|
||||||
|
if msg['message']['chat']['type'] == 'private':
|
||||||
|
chat_title = conf_id
|
||||||
|
else:
|
||||||
|
chat_title = msg['message']['chat']['title']
|
||||||
|
self.db.add_conf(conf_id, chat_title)
|
||||||
|
max_sen = 100
|
||||||
|
try:
|
||||||
|
count = int(msg['message']['text'][8:])
|
||||||
|
if count > max_sen:
|
||||||
|
count = max_sen
|
||||||
|
except:
|
||||||
|
count = 5
|
||||||
|
try:
|
||||||
|
use_all = bool(msg['message']['text'][8:])
|
||||||
|
except:
|
||||||
|
use_all = False
|
||||||
|
if use_all:
|
||||||
|
rand_messages = self.db.get_random_message(count=count)
|
||||||
|
else:
|
||||||
|
rand_messages = self.db.get_random_message(conf_id, count=count)
|
||||||
|
print(count, rand_messages)
|
||||||
|
rand_text = " ".join(rand_messages)
|
||||||
|
gen_text = get(rand_text)
|
||||||
|
try:
|
||||||
|
gen_text = gen_text.lower().capitalize()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.send(id=conf_id, msg=f'{gen_text}')
|
||||||
|
return True
|
||||||
|
|
||||||
|
if input_message == '/stat':
|
||||||
|
conf_id = msg['message']['chat']['id']
|
||||||
|
user_id = msg['message']['from']['id']
|
||||||
|
if msg['message']['chat']['type'] == 'private':
|
||||||
|
chat_title = conf_id
|
||||||
|
else:
|
||||||
|
chat_title = msg['message']['chat']['title']
|
||||||
|
self.db.add_conf(conf_id, chat_title)
|
||||||
|
|
||||||
|
message = """Here is your top:\n"""
|
||||||
|
top = self.db.get_top(
|
||||||
|
user_id=user_id,
|
||||||
|
conf_id=conf_id
|
||||||
|
)
|
||||||
|
for word in top:
|
||||||
|
message += '*%s*: %s\n' % (word[1], word[0])
|
||||||
|
self.send(id=conf_id, msg=message)
|
||||||
|
return True
|
||||||
|
|
||||||
|
if input_message == '/reset':
|
||||||
|
conf_id = msg['message']['chat']['id']
|
||||||
|
user_id = msg['message']['from']['id']
|
||||||
|
if msg['message']['chat']['type'] == 'private':
|
||||||
|
chat_title = conf_id
|
||||||
|
else:
|
||||||
|
chat_title = msg['message']['chat']['title']
|
||||||
|
self.db.add_conf(conf_id, chat_title)
|
||||||
|
|
||||||
|
message = """Your stat has been resetted."""
|
||||||
|
self.db.reset(
|
||||||
|
conf_id=conf_id,
|
||||||
|
user_id=user_id)
|
||||||
|
return True
|
||||||
|
|
||||||
|
if input_message[:4] == '/sql':
|
||||||
|
conf_id = msg['message']['chat']['id']
|
||||||
|
user_id = msg['message']['from']['id']
|
||||||
|
if msg['message']['chat']['type'] == 'private':
|
||||||
|
chat_title = conf_id
|
||||||
|
else:
|
||||||
|
chat_title = msg['message']['chat']['title']
|
||||||
|
self.db.add_conf(conf_id, chat_title)
|
||||||
|
sql = msg['message']['text'][5:]
|
||||||
|
|
||||||
|
res = self.db.command(sql)
|
||||||
|
if 'syntax' in str(res) \
|
||||||
|
or 'ambiguous' in str(res):
|
||||||
|
self.send(id=conf_id, msg=str(res))
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
msg = '```\n'
|
||||||
|
for z in res:
|
||||||
|
for i in z:
|
||||||
|
msg = msg + str(i) + '\t'
|
||||||
|
msg = msg + '\n'
|
||||||
|
except:
|
||||||
|
msg = res
|
||||||
|
self.send(id=conf_id, msg=msg + ' ```')
|
||||||
|
return True
|
||||||
|
|
||||||
|
if input_message[:6] == '/alert':
|
||||||
|
conf_id = msg['message']['chat']['id']
|
||||||
|
user_id = msg['message']['from']['id']
|
||||||
|
if msg['message']['chat']['type'] == 'private':
|
||||||
|
chat_title = conf_id
|
||||||
|
else:
|
||||||
|
chat_title = msg['message']['chat']['title']
|
||||||
|
self.db.add_conf(conf_id, chat_title)
|
||||||
|
msg = msg['message']['text'].split()[1:]
|
||||||
|
alert_time = msg[-1].replace(':', '').replace('.', '').replace(' ', '')
|
||||||
|
if self.isTime(alert_time):
|
||||||
|
message = " ".join(msg[0:-1])
|
||||||
|
self.db.add_alert(user_id, conf_id, alert_time, message)
|
||||||
|
self.send(id=conf_id, msg='Alert created.')
|
||||||
|
return True
|
||||||
|
|
||||||
|
if input_message[:5] == '/code':
|
||||||
|
# codefunc
|
||||||
|
conf_id = msg['message']['chat']['id']
|
||||||
|
user_id = msg['message']['from']['id']
|
||||||
|
if msg['message']['chat']['type'] == 'private':
|
||||||
|
chat_title = conf_id
|
||||||
|
else:
|
||||||
|
chat_title = msg['message']['chat']['title']
|
||||||
|
self.db.add_conf(conf_id, chat_title)
|
||||||
|
if len(msg['message']['text'][6:]) < 10000:
|
||||||
|
try:
|
||||||
|
self.colorize(msg['message']['text'][6:])
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
self.send_img(conf_id)
|
||||||
|
return True
|
||||||
try:
|
try:
|
||||||
text = msg['message']['text']
|
text = msg['message']['text']
|
||||||
username = msg['message']['from']['username']
|
try:
|
||||||
|
username = msg['message']['from']['username']
|
||||||
|
except:
|
||||||
|
username = "_null"
|
||||||
try:
|
try:
|
||||||
last_name = msg['message']['from']['last_name']
|
last_name = msg['message']['from']['last_name']
|
||||||
except:
|
except:
|
||||||
@ -107,36 +321,37 @@ class MessageWorker:
|
|||||||
first_name = '_null'
|
first_name = '_null'
|
||||||
user_id = msg['message']['from']['id']
|
user_id = msg['message']['from']['id']
|
||||||
chat_id = msg['message']['chat']['id']
|
chat_id = msg['message']['chat']['id']
|
||||||
chat_title = msg['message']['chat']['title']
|
if msg['message']['chat']['type'] == 'private':
|
||||||
#print(self.clean_text(text))
|
chat_title = chat_id
|
||||||
|
else:
|
||||||
|
chat_title = msg['message']['chat']['title']
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
print("[%s] (%s) %s %s %s: %s" % (chat_title, user_id, username, first_name, last_name, text))
|
||||||
collection = self.clean_text(text)
|
collection = self.clean_text(text)
|
||||||
|
|
||||||
self.db.add_user(username,
|
self.db.add_user(username,
|
||||||
user_id,
|
user_id,
|
||||||
first_name,
|
first_name,
|
||||||
last_name)
|
last_name)
|
||||||
|
|
||||||
self.db.add_conf(chat_id, chat_title)
|
self.db.add_conf(chat_id, chat_title)
|
||||||
|
|
||||||
for word in collection:
|
for word in collection:
|
||||||
self.db.add_relation(word=word, user_id=user_id, conf_id=chat_id)
|
self.db.add_relation(word=word, user_id=user_id, conf_id=chat_id, text=text)
|
||||||
|
|
||||||
|
|
||||||
def clean_text(self, s):
|
def clean_text(self, s):
|
||||||
file = open(self.stop_words, 'rt')
|
file = open(self.stop_words, 'rt')
|
||||||
sw = file.read().split('\n')
|
sw = file.read().split('\n')
|
||||||
file.close()
|
file.close()
|
||||||
s = re.sub(r'(https?:\/\/)?([\da-z\.-]+)\.([\/\w\.-]*)*\/?\S','',s,flags=re.MULTILINE)
|
s = re.sub(
|
||||||
print(s)
|
r'(https?:\/\/)?([\da-z\.-]+)\.([\/\w\.-]*)*\/?\S', '', s, flags=re.MULTILINE)
|
||||||
# dirty hack with dat fucking file
|
# dirty hack with dat fucking file
|
||||||
fh = open("tmp.txt","w")
|
fh = open("tmp.txt", "w")
|
||||||
fh.write(s)
|
fh.write(s)
|
||||||
fh.close()
|
fh.close()
|
||||||
cmd = "./assets/mystem -nlwd < tmp.txt"
|
cmd = "./assets/mystem -nlwd < tmp.txt"
|
||||||
ps = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
|
ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
|
||||||
output = ps.communicate()[0]
|
output = ps.communicate()[0]
|
||||||
os.remove("tmp.txt")
|
os.remove("tmp.txt")
|
||||||
# end of the fuckin' dirty hack
|
# end of the fuckin' dirty hack
|
||||||
@ -145,7 +360,7 @@ class MessageWorker:
|
|||||||
s = s.split('\n')
|
s = s.split('\n')
|
||||||
collection = []
|
collection = []
|
||||||
for word in s:
|
for word in s:
|
||||||
if len(word) >2:
|
if len(word) > 2:
|
||||||
if word not in sw:
|
if word not in sw:
|
||||||
collection.append(word)
|
collection.append(word)
|
||||||
else:
|
else:
|
||||||
@ -154,18 +369,38 @@ class MessageWorker:
|
|||||||
pass
|
pass
|
||||||
return collection
|
return collection
|
||||||
|
|
||||||
def send(self, id, msg):
|
def send(self, id, msg, parse_mode='Markdown'):
|
||||||
print(msg)
|
# print(msg)
|
||||||
url = settings.parser.get('bot', 'telegram_api') + \
|
url = self.telegram_api + 'bot' + self.telegram_key + '/sendMessage'
|
||||||
'bot'+ settings.parser.get('bot', 'telegram_key') \
|
|
||||||
+ '/sendMessage'
|
|
||||||
post_fields = {
|
post_fields = {
|
||||||
'text': msg,
|
'text': msg,
|
||||||
'chat_id': id,
|
'chat_id': id,
|
||||||
'parse_mode': 'Markdown',
|
'parse_mode': parse_mode,
|
||||||
'disable_web_page_preview': 1
|
'disable_web_page_preview': 1
|
||||||
}
|
}
|
||||||
urllib.request.Request(url, urlencode(post_fields).encode())
|
urllib.request.Request(url, urlencode(post_fields).encode())
|
||||||
request = urllib.request.Request(url, urlencode(post_fields).encode())
|
request = urllib.request.Request(url, urlencode(post_fields).encode())
|
||||||
json = urllib.request.urlopen(request).read().decode()
|
json = urllib.request.urlopen(request).read().decode()
|
||||||
return json
|
return json
|
||||||
|
|
||||||
|
def send_img(self, id):
|
||||||
|
print('Going to send code.png to %s' % id)
|
||||||
|
try:
|
||||||
|
url = self.telegram_api + 'bot' + self.telegram_key + '/sendPhoto'
|
||||||
|
data = {'chat_id': id}
|
||||||
|
files = {'photo': open('code.png', 'rb')}
|
||||||
|
r = requests.post(url, files=files, data=data)
|
||||||
|
#print(r)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
def cron_timer(self):
|
||||||
|
alerts = self.db.get_alert()
|
||||||
|
for alert in alerts:
|
||||||
|
users = self.db.all_conf_users(conf_id=alert[0])
|
||||||
|
msg = ""
|
||||||
|
for user in users:
|
||||||
|
msg += ' [%s](tg://user?id=%s) ' % (user[1], user[2])
|
||||||
|
msg += "\nHey all!\n%s" % alert[4]
|
||||||
|
self.send(id=alert[0], msg=msg)
|
||||||
|
threading.Timer(30, self.cron_timer).start()
|
||||||
|
Reference in New Issue
Block a user