From e09ffd6fa6bbc466d81c20dff8614cb928876087 Mon Sep 17 00:00:00 2001 From: AB Date: Thu, 24 Oct 2019 13:17:20 +0000 Subject: [PATCH] It works again. --- assets/cert.sh | 3 +- assets/main.db.sql | 101 ++---- puller.py | 76 +++++ vim-session | 822 +++++++++++++++++++++++++++++++++++++++++++++ worker.py | 319 ++++++++++-------- 5 files changed, 1108 insertions(+), 213 deletions(-) create mode 100644 puller.py create mode 100644 vim-session diff --git a/assets/cert.sh b/assets/cert.sh index 9eb390b..3ca95e1 100755 --- a/assets/cert.sh +++ b/assets/cert.sh @@ -1 +1,2 @@ -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=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.hexor.ru" + diff --git a/assets/main.db.sql b/assets/main.db.sql index 715d38d..62046ec 100755 --- a/assets/main.db.sql +++ b/assets/main.db.sql @@ -1,87 +1,39 @@ -BEGIN TRANSACTION; - ---- CREATE TABLE `word` ( ---- `id` INTEGER PRIMARY KEY AUTOINCREMENT, ---- `word` TEXT UNIQUE ---- ); ---- CREATE TABLE sqlite_sequence(name,seq); ---- CREATE TABLE `user` ( ---- `id` INTEGER NOT NULL UNIQUE, ---- `username` TEXT NOT NULL, ---- `first_name` TEXT NOT NULL, ---- `last_name` TEXT NOT NULL, ---- `date` INTEGER NOT NULL, ---- PRIMARY KEY(`id`) ---- ); ---- CREATE TABLE `conf` ( ---- `id` NUMERIC NOT NULL UNIQUE, ---- `title` TEXT, ---- `date` INTEGER NOT NULL, ---- PRIMARY KEY(`id`) ---- ); ---- CREATE TABLE `xxx_message` (`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `text` TEXT UNIQUE NULL); ---- CREATE TABLE IF NOT EXISTS "relations" ( ---- `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ---- `word_id` INTEGER NOT NULL, ---- `user_id` INTEGER NOT NULL, ---- `conf_id` INTEGER NOT NULL, ---- `msg_id` INTEGER NOT NULL, ---- `date` INTEGER NOT NULL, ---- FOREIGN KEY(`word_id`) REFERENCES `word`(`id`) ON DELETE CASCADE, ---- FOREIGN KEY(`user_id`) REFERENCES `user`(`id`), ---- FOREIGN KEY(`conf_id`) REFERENCES `conf`(`id`) ---- ); ---- CREATE TABLE `reset` ( ---- `id` INTEGER PRIMARY KEY AUTOINCREMENT, ---- `user_id` INTEGER, ---- `conf_id` INTEGER, ---- `date` INTEGER, ---- `relation_id` INTEGER, ---- FOREIGN KEY(`user_id`) REFERENCES `user`(`id`) ---- ); ---- 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 `word` ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT, - `word` TEXT UNIQUE + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `word` TEXT UNIQUE ); CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE `user` ( - `id` INTEGER NOT NULL UNIQUE, - `username` TEXT NOT NULL, - `first_name` INTEGER NOT NULL, - `last_name` INTEGER NOT NULL, - `date` INTEGER NOT NULL, - PRIMARY KEY(`id`) + `id` INTEGER NOT NULL UNIQUE, + `username` TEXT NOT NULL, + `first_name` INTEGER NOT NULL, + `last_name` INTEGER NOT NULL, + `date` INTEGER NOT NULL, + PRIMARY KEY(`id`) ); CREATE TABLE `conf` ( - `id` NUMERIC NOT NULL UNIQUE, - `title` TEXT, - `date` INTEGER NOT NULL, - PRIMARY KEY(`id`) + `id` NUMERIC NOT NULL UNIQUE, + `title` TEXT, + `date` INTEGER NOT NULL, + PRIMARY KEY(`id`) ); CREATE TABLE IF NOT EXISTS "relations" ( - `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - `word_id` INTEGER NOT NULL, - `user_id` INTEGER NOT NULL, - `conf_id` INTEGER NOT NULL, - `date` INTEGER NOT NULL, `msg_id` INTEGER NULL, - FOREIGN KEY(`word_id`) REFERENCES `word`(`id`) ON DELETE CASCADE, - FOREIGN KEY(`user_id`) REFERENCES `user`(`id`), - FOREIGN KEY(`conf_id`) REFERENCES `conf`(`id`) + `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + `word_id` INTEGER NOT NULL, + `user_id` INTEGER NOT NULL, + `conf_id` INTEGER NOT NULL, + `date` INTEGER NOT NULL, `msg_id` INTEGER NULL, + FOREIGN KEY(`word_id`) REFERENCES `word`(`id`) ON DELETE CASCADE, + FOREIGN KEY(`user_id`) REFERENCES `user`(`id`), + FOREIGN KEY(`conf_id`) REFERENCES `conf`(`id`) ); CREATE TABLE `reset` ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT, - `user_id` INTEGER, - `conf_id` INTEGER, - `date` INTEGER, - `relation_id` INTEGER, - FOREIGN KEY(`user_id`) REFERENCES `user`(`id`) + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `user_id` INTEGER, + `conf_id` INTEGER, + `date` INTEGER, + `relation_id` INTEGER, + FOREIGN KEY(`user_id`) REFERENCES `user`(`id`) ); CREATE TABLE `alert` ( `conf_id`TEXT NOT NULL, @@ -91,4 +43,3 @@ CREATE TABLE `alert` ( `message`TEXT ); CREATE TABLE `xxx_message` (`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `text`TEXT UNIQUE NULL); -COMMIT; diff --git a/puller.py b/puller.py new file mode 100644 index 0000000..c1d4976 --- /dev/null +++ b/puller.py @@ -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() diff --git a/vim-session b/vim-session new file mode 100644 index 0000000..b1dec7c --- /dev/null +++ b/vim-session @@ -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 NetrwBrowseXVis +nmap gx NetrwBrowseX +vnoremap NetrwBrowseXVis :call netrw#BrowseXVis() +nnoremap NetrwBrowseX :call netrw#BrowseX(expand((exists("g:netrw_gx")? g:netrw_gx : '')),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(":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(":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 : diff --git a/worker.py b/worker.py index 5232cf3..5648a49 100755 --- a/worker.py +++ b/worker.py @@ -65,166 +65,208 @@ class MessageWorker: print("Lexer is defined as %s" % lexer) if lexer.name == 'Text only': lexer = get_lexer_by_name('python') - try: - 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") - except Exception as e: - print(e) - return e + 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): try: - try: - input_message = msg['message']['text'] - 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'] - user_id = msg['message']['from']['id'] - chat_title = msg['message']['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""" - - users = self.db.here( - user_id=user_id, - conf_id=conf_id - ) - for user in users: - message += ' [%s](tg://user?id=%s)' % (user[2], user[1]) - self.send(id=conf_id, msg=message) - return True - - input_message = msg['message']['text'].replace( - '@' + self.me['result']['username'], '') - except: - 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'] - 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'] - 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'] - 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': + input_message = msg['message']['text'] + if input_message == '/help': conf_id = msg['message']['chat']['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.send(id=conf_id, msg='```\n' + self.db.scheme + '\n```') - return True - - if input_message == '/stat': + msg = """ + Commands: + @here - call all conf users + /stat - show user stat + /scheme - print sql schema + /reset - reset user stat + /sql - execute sql + /alert - set alert + /code - highlight code snippet + """ + self.send(id=conf_id, msg=msg) + 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'] 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) + 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 = """Here is your top:\n""" - top = self.db.get_top( + users = self.db.here( user_id=user_id, conf_id=conf_id ) - for word in top: - message += '*%s*: %s\n' % (word[1], word[0]) + for user in users: + message += ' [%s](tg://user?id=%s)' % (user[2], user[1]) 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'] + + input_message = msg['message']['text'].replace( + '@' + self.me['result']['username'], '') + except: + 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.db.add_conf(conf_id, chat_title) + self.send(id=conf_id, msg='```\n' + self.db.scheme + '\n```') + return True - 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 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) - sql = msg['message']['text'][5:] + self.db.add_conf(conf_id, chat_title) - 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 + 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[:6] == '/alert': - conf_id = msg['message']['chat']['id'] - user_id = msg['message']['from']['id'] + 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) - 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 + self.db.add_conf(conf_id, chat_title) - if input_message[:5] == '/code': + 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'] + 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 - except Exception as e: - print('ERROR: %s' % e) - return False + 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: text = msg['message']['text'] try: @@ -241,7 +283,10 @@ class MessageWorker: first_name = '_null' user_id = msg['message']['from']['id'] chat_id = msg['message']['chat']['id'] - chat_title = msg['message']['chat']['title'] + if msg['message']['chat']['type'] == 'private': + chat_title = chat_id + else: + chat_title = msg['message']['chat']['title'] except: return False print("[%s] (%s) %s %s %s: %s" % (chat_title, user_id, username, first_name, last_name, text))