Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/isida/vi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiSabler <dissy@ya.ru>2020-03-28 13:51:49 +0300
committerdiSabler <dissy@ya.ru>2020-03-28 13:51:49 +0300
commit3299f94832530db35152dde5fde1a46046c0fb6d (patch)
tree5d36779d8c5dc874f60fdd22ff7d685b504bc881
parent57773cbc08cac160a4292f4bcdd7709b39d21490 (diff)
add: event plugin
-rw-r--r--plugins/event.py100
1 files changed, 100 insertions, 0 deletions
diff --git a/plugins/event.py b/plugins/event.py
new file mode 100644
index 0000000..c9c03ef
--- /dev/null
+++ b/plugins/event.py
@@ -0,0 +1,100 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# --------------------------------------------------------------------------- #
+# #
+# iSida bot VI plugin #
+# Copyright (C) diSabler <dsy@dsy.name> #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+# --------------------------------------------------------------------------- #
+
+EVENTS = {}
+
+def make_name(FROM):
+ USERNAME = FROM.get('username', '')
+ FIRST = FROM.get('first_name', '')
+ LAST = FROM.get('last_name', '')
+ NAME = ' '.join(t for t in [FIRST, LAST] if t)
+ if NAME and USERNAME:
+ return '%s [@%s]' % (NAME, USERNAME)
+ elif USERNAME:
+ return '@%s' % USERNAME
+ elif NAME:
+ return NAME
+ else:
+ return 'id%' % FROM['id']
+
+def cmd_event(raw_in, less):
+ global EVENTS
+ MESSAGE = raw_in.get('message', {})
+ CHAT = MESSAGE.get('chat', {})
+ if CHAT.get('type', '') == 'group':
+ if not less and raw_in['message'].has_key('reply_to_message'):
+ if raw_in['message']['reply_to_message'].has_key('text'):
+ less = raw_in['message']['reply_to_message']['text']
+ if less:
+ CHAT_ID = CHAT['id']
+ FROM = MESSAGE['from']
+ USER_ID = FROM['id']
+ EVENT_NAME = less.capitalize().replace(' ', '_')
+ EVENTS[CHAT_ID] = EVENTS.get(CHAT_ID, {})
+ if EVENTS[CHAT_ID].has_key(EVENT_NAME):
+ if USER_ID == EVENTS[CHAT_ID][EVENT_NAME]['id']:
+ msg = '❎ Event `%s` removed' % EVENT_NAME
+ _ = EVENTS[CHAT_ID].pop(EVENT_NAME)
+ else:
+ name = make_name(EVENTS[CHAT_ID][EVENT_NAME])
+ msg = '⛔️ Event `%s` already exists\nCreated by %s' % (EVENT_NAME, name)
+ else:
+ EVENTS[CHAT_ID][EVENT_NAME] = FROM
+ msg = '✅ Created new event `%s`\nUse %s for remove it' % (EVENT_NAME, MESSAGE['text'].lower().replace(' ', '_'))
+ else:
+ msg = '⚠️ Required parameter missed!'
+ else:
+ msg = 'Works only in groups!'
+ send_msg(raw_in, msg)
+
+def cmd_events(raw_in):
+ global EVENTS
+ MESSAGE = raw_in.get('message', {})
+ CHAT = MESSAGE.get('chat', {})
+ if CHAT.get('type', '') == 'group':
+ CHAT_ID = CHAT['id']
+ FROM = MESSAGE['from']
+ USER_ID = FROM['id']
+ EVENTS[CHAT_ID] = EVENTS.get(CHAT_ID, {})
+ if EVENTS[CHAT_ID]:
+ msg = []
+ for EVENT_NAME in EVENTS[CHAT_ID].keys():
+ if USER_ID == EVENTS[CHAT_ID][EVENT_NAME]['id']:
+ msg.append('✅ /event_%s' % EVENT_NAME)
+ else:
+ name = make_name(EVENTS[CHAT_ID][EVENT_NAME])
+ msg.append('⛔️ /event_%s - %s' % (EVENT_NAME, name))
+ msg.sort()
+ msg = '\n'.join(msg)
+ else:
+ msg = '✅ No events in current group'
+ else:
+ msg = 'Works only in groups!'
+ send_msg(raw_in, msg)
+
+commands = [
+ ['event', cmd_event, False, 'all', 'Create lock for event'],
+ ['events', cmd_events, False, 'raw', 'Show current events']
+]
+
+# The end is near!