Ejemplo n.º 1
0
def telegram():
    try:
        text = request.data.decode("utf8")
        process.delay(text)
    except Exception:
        EC = EthicsCommittee(0, 0)
        EC.log(traceback.format_exc())
    return "OK"
Ejemplo n.º 2
0
def web():
    if "q" in request.args:
        if request.args['q'] in webs:
            try:
                return webs[request.args['q']].web()
            except (AttributeError, NotImplementedError):
                EC = EthicsCommittee(0, 0)
                EC.log(traceback.format_exc())
                return "This module doesn't have web."
        else:
            return "No such module."
    else:
        return "Not given module name."
Ejemplo n.º 3
0
def process(self, text):  # pylint: disable=W0613
    logging.info(text)
    try:
        data = json.loads(text)
        if 'message' in data and int(
                data['message']['date']) < time.time() - 600:
            logging.warning('\tignore')
            return None
        EC = EthicsCommittee(update=data)
        for extension in extensions:
            try:
                extension.main(EC)
            except NotImplementedError:
                EC = EthicsCommittee(0, 0)
                EC.log(traceback.format_exc())
    except Exception:
        EC = EthicsCommittee(0, 0)
        EC.log(traceback.format_exc())
    return None
Ejemplo n.º 4
0
 def web(self):
     EC = EthicsCommittee(0, 0)
     EC.cur.execute(
         """SELECT `user_id`, `old_name`, `new_name`, `time` FROM `user_name_changes`
         ORDER BY `time` DESC LIMIT 500""")
     rows = EC.cur.fetchall()
     text = """<!DOCTYPE html>
         <html>
         <head>
             <style>
             table {
                 border-collapse: collapse;
             }
             th, td {
                 vertical-align: top;
                 border: 1px solid black;
                 padding: 3px;
             }
             </style>
         </head>
         <body>
         <table>
         <thead>
         <tr>
             <th>user_id</th>
             <th>old_name</th>
             <th>new_name</th>
             <th>time</th>
         </tr>
         </thead>
         <tbody>
         """
     for row in rows:
         text += """<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>""".format(
             row[0], row[1], row[2], row[3])
     text += """
         </tbody>
         </table>
         </body>
         </html>
         """
     return text
Ejemplo n.º 5
0
    def __init__(self, notice_chat_ids):
        self.chat_ids = notice_chat_ids

        EC = EthicsCommittee(0, 0)

        self.usernames = {}
        EC.cur.execute(
            """SELECT `user_id`, `full_name`, `username` FROM `user_name`""")
        rows = EC.cur.fetchall()
        for row in rows:
            self.usernames[row[0]] = [row[1], row[2]]
        print('[UpdateUsername] Get {} usernames'.format(len(self.usernames)))

        self.groupnames = {}
        EC.cur.execute(
            """SELECT `chat_id`, `title`, `username` FROM `group_name`""")
        rows = EC.cur.fetchall()
        for row in rows:
            self.groupnames[row[0]] = [row[1], row[2]]
        print('[UpdateUsername] Get {} groupnames'.format(len(
            self.groupnames)))
Ejemplo n.º 6
0
 def web(self):
     EC = EthicsCommittee(0, 0)
     EC.cur.execute(
         """SELECT `message`, `time` FROM `log` ORDER BY `log_id` DESC LIMIT 100"""
     )
     rows = EC.cur.fetchall()
     text = """<!DOCTYPE html>
         <html>
         <head>
             <style>
             table {
                 border-collapse: collapse;
             }
             th, td {
                 vertical-align: top;
                 border: 1px solid black;
                 padding: 3px;
             }
             pre {
                 margin-top: 0;
                 white-space: pre-wrap;
             }
         </style>
         </head>
         <body>
         <table>
         <tr>
         <td>time</td>
         <td>log</td>
         </tr>
         """
     for row in rows:
         text += "<tr><td>{0}</td><td><pre>{1}</pre></td></tr>".format(
             row[1], row[0])
     text += """
         </table>
         </body>
         </html>
         """
     return text
Ejemplo n.º 7
0
 def web(self):
     EC = EthicsCommittee(0, 0)
     EC.cur.execute(
         """SELECT `chat_id`, `admins`.`user_id`, `full_name`, `creator` FROM `admins`
         LEFT JOIN `user_name` ON `admins`.`user_id` = `user_name`.`user_id`
         WHERE `chat_id` IN
         ({})""".format(self.chat_id_list))
     rows = EC.cur.fetchall()
     admin_in_chats = set()
     admins = set()
     creators = set()
     for row in rows:
         admin_in_chats.add((row[0], row[1]))
         admins.add((row[1], row[2]))
         if row[3]:
             creators.add((row[0], row[1]))
     EC.cur.execute(
         """SELECT `chat_id`, `title` FROM `group_name`
         WHERE `chat_id` IN ({})""".format(self.chat_id_list))
     groups = EC.cur.fetchall()
     text = """<!DOCTYPE html>
         <html>
         <head>
             <style>
             table {
                 border-collapse: collapse;
                 table-layout: fixed;
                 width: 100%;
             }
             thead tr th {
                 position:sticky;
                 top:0;
             }
             th {
                 background-color: #bbeeaa;
                 word-break: break-all;
             }
             th, td {
                 vertical-align: top;
                 border: 1px solid black;
                 padding: 3px;
             }
             th:first-child {
                 z-index:2;
                 background-color: #bbeeaa;
             }
             td:first-child, th:first-child {
                 position:sticky;
                 left:0;
                 z-index:1;
                 background-color: #ffffbb;
             }
             td {
                 word-break: break-all;
             }
             .groupname {
                 width: 80px;
             }
             .username {
                 width: 100px;
             }
             .creator {
                 background-color: #ffaaff;
             }
         </style>
         </head>
         <body>
         <table>
         <thead>
         <tr>
         <th class="username"></th>
         """
     for group in groups:
         text += """<th class="groupname"><span title="{0}">{1}</span></th>""".format(
             group[0], group[1])
     text += """
         </tr>
         </thead>
         <tbody>
         """
     for admin in admins:
         text += """<tr><td class="username"><span title="{0}">{1}</span></td>""".format(
             admin[0], admin[1] if admin[1] is not None else admin[0])
         for group in groups:
             if (group[0], admin[0]) in creators:
                 text += """<td class="creator">"""
             else:
                 text += "<td>"
             if (group[0], admin[0]) in admin_in_chats:
                 text += '&#10003;'
             text += "</td>"
         text += "</tr>"
     text += """
         </tbody>
         </table>
         </body>
         </html>
         """
     return text
Ejemplo n.º 8
0
 def web(self):
     EC = EthicsCommittee(0, 0)
     EC.cur.execute("""SELECT
             `admins_changes`.`chat_id`,
             `group_name`.`title`,
             `admins_changes`.`user_id`,
             `user_name`.`full_name`,
             `user_name`.`username`,
             `admins_changes`.`action`,
             `admins_changes`.`can_add_web_page_previews`,
             `admins_changes`.`can_be_edited`,
             `admins_changes`.`can_change_info`,
             `admins_changes`.`can_delete_messages`,
             `admins_changes`.`can_edit_messages`,
             `admins_changes`.`can_invite_users`,
             `admins_changes`.`can_pin_messages`,
             `admins_changes`.`can_post_messages`,
             `admins_changes`.`can_promote_members`,
             `admins_changes`.`can_restrict_members`,
             `admins_changes`.`can_send_media_messages`,
             `admins_changes`.`can_send_messages`,
             `admins_changes`.`can_send_other_messages`,
             `admins_changes`.`time`
         FROM `admins_changes`
         LEFT JOIN `group_name`
         ON `admins_changes`.`chat_id` = `group_name`.`chat_id`
         LEFT JOIN `user_name`
         ON `admins_changes`.`user_id` = `user_name`.`user_id`
         ORDER BY `time` DESC""")
     rows = EC.cur.fetchall()
     text = """<!DOCTYPE html>
         <html>
         <head>
             <style>
             table {
                 border-collapse: collapse;
             }
             th, td {
                 vertical-align: top;
                 border: 1px solid black;
                 padding: 3px;
             }
             </style>
         </head>
         <body>
         <table>
         <thead>
         <tr>
             <th>chat_id</th>
             <th>chat_title</th>
             <th>user_id</th>
             <th>user_full_name</th>
             <th>username</th>
             <th>action</th>
             <th>can_add_web_page_previews</th>
             <th>can_be_edited</th>
             <th>can_change_info</th>
             <th>can_delete_messages</th>
             <th>can_edit_messages</th>
             <th>can_invite_users</th>
             <th>can_pin_messages</th>
             <th>can_post_messages</th>
             <th>can_promote_members</th>
             <th>can_restrict_members</th>
             <th>can_send_media_messages</th>
             <th>can_send_messages</th>
             <th>can_send_other_messages</th>
             <th>time</th>
         </tr>
         </thead>
         <tbody>
         """
     for row in rows:
         text += '<tr>'
         for i in range(20):
             text += '<td>{}</td>'.format(row[i])
         text += '</tr>'
     text += """
         </tbody>
         </table>
         </body>
         </html>
         """
     return text
    def web(self):
        EC = EthicsCommittee(0, 0)

        html = """
            <style>
                table {
                    border-collapse: collapse;
                }
                th, td {
                    vertical-align: top;
                    border: 1px solid black;
                    padding: 3px;
                }
            </style>
            """
        html += """
            source
            <table>
            <tr>
            <th>chat</th>
            <th>command</th>
            </tr>
            """
        for chat_id in self.settings['source']:
            if chat_id in self.hidden_in_web:
                continue
            setting = self.settings['source'][chat_id]

            html += """<tr>"""
            html += """<td>{0}<br>{1}</td>""".format(
                EC.get_group_name(chat_id),
                chat_id,
            )
            html += """
                <td>
                <table>
                <tr>
                <th>command</th>
                <th>target</th>
                <th>accept</th>
                <th>deny</th>
                </tr>
                """
            for cmd in setting:
                html += """<tr>"""
                html += """<td>{0}</td><td>{1} {2}</td><td>{3}</td><td>{4}</td>""".format(
                    cmd,
                    EC.get_group_name(setting[cmd]['chat_id']),
                    setting[cmd]['chat_id'],
                    setting[cmd]['accept'],
                    setting[cmd]['deny'],
                )
                html += """</tr>"""
            html += """</table></td>"""
            html += """</tr>"""
        html += """</table>"""

        html += """
            target
            <table>
            <tr>
            <th>chat</th>
            <th>grant permission</th>
            <th>revoke permission</th>
            </tr>
            """
        for chat_id in self.settings['target']:
            if chat_id in self.hidden_in_web:
                continue
            setting = self.settings['target'][chat_id]

            html += """<tr>"""
            html += """<td>{0}<br>{1}</td><td>{2}</td><td>{3}</td>""".format(
                EC.get_group_name(chat_id),
                chat_id,
                setting['permissions']['grant'],
                setting['permissions']['revoke'],
            )
            html += """</tr>"""
        html += """</table>"""

        return html
Ejemplo n.º 10
0
import telegram
sys.path.insert(
    0, os.path.realpath(os.path.dirname(os.path.realpath(__file__)) + '/../'))
from Kamisu66 import EthicsCommittee
from wiki_admins_config import CHATS, TGNAME  # pylint: disable=E0401

parser = argparse.ArgumentParser()
parser.add_argument('group')
parser.add_argument('--dry-run', dest='dry_run', action='store_true')
parser.add_argument('--new-message', dest='new', action='store_true')
parser.add_argument('--empty-message', dest='empty', action='store_true')
parser.set_defaults(dry_run=False, new=False, empty=False)
args = parser.parse_args()
print(args)

EC = EthicsCommittee(0, 0)

if args.group not in CHATS:
    exit('chat not found')

setting = CHATS[args.group]

print(setting)

text = ''
if args.empty:
    text = '(empty)'
else:
    for group in setting['groups']:
        print(group[0])
        text += '{}:\n'.format(group[1])
Ejemplo n.º 11
0
    def web(self):
        EC = EthicsCommittee(0, 0)

        html = """
            <style>
                table {
                    border-collapse: collapse;
                }
                th, td {
                    vertical-align: top;
                    border: 1px solid black;
                    padding: 3px;
                }
            </style>
        <table>
        <tr>
        <th>chat</th>
        <th>command</th>
        <th>permission grant</th>
        <th>permission change_logo</th>
        </tr>
        """
        for chat_id in self.settings:
            if chat_id in self.hidden_in_web:
                continue
            setting = self.settings[chat_id]

            html += """<tr>"""
            html += """<td>{0}<br>{1}</td>""".format(
                EC.get_group_name(chat_id),
                chat_id,
            )
            html += """<td>"""
            html += """grant permission<br><ul><li>{0}</li></ul>""".format(
                setting['permissions']['grant'], )
            html += """revoke permission<br><ul><li>{0}</li></ul>""".format(
                setting['permissions']['revoke'], )
            html += """change logo<br><ul>"""
            for cmd in setting['logo']:
                html += """<li>{0}</li>""".format(cmd)
            html += """<ul>"""

            html += """</td>"""

            html += """<td><ul>"""
            EC.cur.execute(
                """SELECT `permissions`.`user_id`, `full_name` FROM `permissions` LEFT JOIN `user_name` ON `permissions`.`user_id` = `user_name`.`user_id` WHERE `chat_id` = %s AND `user_right` = %s ORDER BY `permissions`.`user_id` ASC""",
                (chat_id, self.PERMISSION_GRANT))
            rows = EC.cur.fetchall()
            for row in rows:
                html += """<li>{0}({1})</li>""".format(row[0], row[1])
            html += """<ul></td>"""

            html += """<td><ul>"""
            EC.cur.execute(
                """SELECT `permissions`.`user_id`, `full_name` FROM `permissions` LEFT JOIN `user_name` ON `permissions`.`user_id` = `user_name`.`user_id` WHERE `chat_id` = %s AND `user_right` = %s ORDER BY `permissions`.`user_id` ASC""",
                (chat_id, self.PERMISSION_CHANGELOGO))
            rows = EC.cur.fetchall()
            for row in rows:
                html += """<li>{0}({1})</li>""".format(row[0], row[1])
            html += """<ul></td>"""

            html += """</tr>"""
        html += """</table>"""

        return html
Ejemplo n.º 12
0
# -*- coding: utf-8 -*-
import os
import sys
import time

sys.path.insert(0, os.path.realpath(
    os.path.dirname(os.path.realpath(__file__)) + "/../"))
from config_variable import cfg  # pylint: disable=E0401
from Kamisu66 import EthicsCommittee

print(cfg)

EC = EthicsCommittee(0, 0)

dellimit = int(time.time() - 86400 * 2)

EC.cur.execute("""DELETE FROM `message` WHERE `date` < %s""",
               (int(time.time() - cfg['ImpureCat']['messageskeep'])))
EC.db.commit()

for delconfig in cfg['ImpureCat']['delconfigs']:
    chat_id = delconfig[0]
    deltime = int(time.time() - delconfig[1])
    print(chat_id, deltime)
    EC.cur.execute("""SELECT * FROM `message`
                    WHERE `chat_id` = %s AND `date` < %s AND `date` > %s AND `deleted` = 0 ORDER BY `date`""",
                   (chat_id, str(deltime), str(dellimit)))
    rows = EC.cur.fetchall()
    for row in rows:
        message_id = row[2]
        print(row, message_id)