mirror of
https://github.com/house-of-vanity/conf_bot.git
synced 2025-07-06 14:24:08 +00:00
test
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@ -0,0 +1,4 @@
|
|||||||
|
assets/cert*
|
||||||
|
**/settings.ini
|
||||||
|
main.db
|
||||||
|
settings.ini
|
0
assets/cert.sh
Normal file → Executable file
0
assets/cert.sh
Normal file → Executable file
3
assets/main.db.sql
Normal file → Executable file
3
assets/main.db.sql
Normal file → Executable file
@ -2,6 +2,7 @@ BEGIN TRANSACTION;
|
|||||||
-- DROP TABLE IF EXISTS `word`;
|
-- DROP TABLE IF EXISTS `word`;
|
||||||
CREATE TABLE IF NOT EXISTS `word` (
|
CREATE TABLE IF NOT EXISTS `word` (
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
`is_russian` INTEGER NOT NULL,
|
||||||
`word` TEXT UNIQUE
|
`word` TEXT UNIQUE
|
||||||
);
|
);
|
||||||
-- DROP TABLE IF EXISTS `user`;
|
-- DROP TABLE IF EXISTS `user`;
|
||||||
@ -21,7 +22,7 @@ CREATE TABLE IF NOT EXISTS `relations` (
|
|||||||
`conf_id` INTEGER NOT NULL,
|
`conf_id` INTEGER NOT NULL,
|
||||||
`date` INTEGER NOT NULL,
|
`date` INTEGER NOT NULL,
|
||||||
FOREIGN KEY(`conf_id`) REFERENCES `conf`(`id`),
|
FOREIGN KEY(`conf_id`) REFERENCES `conf`(`id`),
|
||||||
FOREIGN KEY(`word_id`) REFERENCES `word`(`id`) ON DELETE CASCADE,
|
FOREIGN KEY(`word_id`) REFERENCES `word`(`id`),
|
||||||
FOREIGN KEY(`user_id`) REFERENCES `user`(`id`)
|
FOREIGN KEY(`user_id`) REFERENCES `user`(`id`)
|
||||||
);
|
);
|
||||||
-- DROP TABLE IF EXISTS `conf`;
|
-- DROP TABLE IF EXISTS `conf`;
|
||||||
|
BIN
assets/mystem
Executable file
BIN
assets/mystem
Executable file
Binary file not shown.
3
assets/settings.ini.example
Executable file
3
assets/settings.ini.example
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
[bot]
|
||||||
|
telegram_key = 53004316d:dv0YexIXGHvmNojcD2mUaslKs0
|
||||||
|
telegram_api = https://api.telegram.org/
|
0
assets/stop-word.ru
Normal file → Executable file
0
assets/stop-word.ru
Normal file → Executable file
17
conf-bot.service
Normal file
17
conf-bot.service
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Telegram spy bot.
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=ab
|
||||||
|
Group=ab
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
StartLimitInterval=60s
|
||||||
|
StartLimitBurst=3
|
||||||
|
WorkingDirectory=/var/lib/conf_bot
|
||||||
|
ExecStart=/usr/bin/python3 /var/lib/conf_bot/main.py
|
||||||
|
ExecStop=killall -TERM /usr/bin/python3 /var/lib/conf_bot/main.py
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
|
|
15
database.py
Normal file → Executable file
15
database.py
Normal file → Executable file
@ -91,6 +91,21 @@ class DataBase:
|
|||||||
result = self.execute(sql)
|
result = self.execute(sql)
|
||||||
return(result)
|
return(result)
|
||||||
|
|
||||||
|
def here(self, user_id, conf_id):
|
||||||
|
sql= """
|
||||||
|
select distinct(u.username) 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' and
|
||||||
|
u.id != '%s'
|
||||||
|
""" % (
|
||||||
|
conf_id,
|
||||||
|
user_id
|
||||||
|
)
|
||||||
|
result = self.execute(sql)
|
||||||
|
return(result)
|
||||||
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.conn.close()
|
self.conn.close()
|
4
main.py
Normal file → Executable file
4
main.py
Normal file → Executable file
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from webhook import WebHook
|
from webhook import WebHook
|
||||||
import settings
|
import settings
|
||||||
@ -15,6 +15,6 @@ signal.signal(signal.SIGINT, signal_handler)
|
|||||||
wh = WebHook(
|
wh = WebHook(
|
||||||
certfile = 'assets/cert.pem',
|
certfile = 'assets/cert.pem',
|
||||||
keyfile='assets/cert.key',
|
keyfile='assets/cert.key',
|
||||||
port=8080)
|
port=8443)
|
||||||
|
|
||||||
wh.serve()
|
wh.serve()
|
0
settings.py
Normal file → Executable file
0
settings.py
Normal file → Executable file
0
webhook.py
Normal file → Executable file
0
webhook.py
Normal file → Executable file
18
worker.py
Normal file → Executable file
18
worker.py
Normal file → Executable file
@ -8,6 +8,7 @@ import os
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
import settings
|
import settings
|
||||||
|
import re
|
||||||
|
|
||||||
class MessageWorker:
|
class MessageWorker:
|
||||||
def __init__(self, db, stop_words = 'assets/stop-word.ru'):
|
def __init__(self, db, stop_words = 'assets/stop-word.ru'):
|
||||||
@ -31,6 +32,21 @@ class MessageWorker:
|
|||||||
message += '*%s*: %s\n' % (word[1], word[0])
|
message += '*%s*: %s\n' % (word[1], word[0])
|
||||||
self.send(id=conf_id, msg=message)
|
self.send(id=conf_id, msg=message)
|
||||||
return True
|
return True
|
||||||
|
if msg['message']['text'] == '@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(
|
||||||
|
user_id=user_id,
|
||||||
|
conf_id=conf_id
|
||||||
|
)
|
||||||
|
for user in users:
|
||||||
|
message += '@%s ' % (user[0])
|
||||||
|
self.send(id=conf_id, msg=message)
|
||||||
|
return True
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
@ -68,6 +84,8 @@ class MessageWorker:
|
|||||||
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)
|
||||||
|
print(s)
|
||||||
# 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)
|
||||||
|
Reference in New Issue
Block a user