script for new chan like message filter
This commit is contained in:
parent
bbcea10237
commit
434e5a91ad
58
chan-like/channer.py
Normal file
58
chan-like/channer.py
Normal file
@ -0,0 +1,58 @@
|
||||
# Channer front-end
|
||||
|
||||
from os import getenv
|
||||
import argparse
|
||||
import mysql.connector as sql
|
||||
|
||||
CONFIG = {
|
||||
'database': getenv('DATABASE_NAME'),
|
||||
'password': getenv('DATABASE_PASS'),
|
||||
'user': getenv('DATABASE_USER'),
|
||||
'host': getenv('DATABASE_HOST'),
|
||||
'port': int(getenv('DATABASE_PORT')),
|
||||
}
|
||||
|
||||
def add_message_limit(limit: int):
|
||||
count_query = '''
|
||||
SELECT channel_name, COUNT(time) FROM messages
|
||||
GROUP BY channel_name;
|
||||
'''
|
||||
conn = sql.connect(**CONFIG)
|
||||
cursor = conn.cursor()
|
||||
|
||||
|
||||
def add_message_timeout():
|
||||
pass
|
||||
|
||||
def rm_message_limit():
|
||||
pass
|
||||
|
||||
def rm_message_timeout():
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(
|
||||
description='An optional microservice for freechat to make the messaging system more transient'
|
||||
)
|
||||
|
||||
parser.add_argument('-t', '--time-out', type=float, required=False)
|
||||
parser.add_argument('-m', '--message-limit', type=int, required=False)
|
||||
parser.add_argument('-r', '--remove' type=string, required=False, choices=['timeout', 'limit'])
|
||||
|
||||
|
||||
args = vars(parser.parse_args())
|
||||
|
||||
limit = args['message_limit']
|
||||
timeout = args['time_out']
|
||||
|
||||
# timeout is given in days 30 => 30 day time limit
|
||||
if limit: add_message_limit(limit)
|
||||
if timeout: add_message_timeout(timeout)
|
||||
|
||||
if args['remove']:
|
||||
remove_opts = {
|
||||
'timeout': rm_message_timeout,
|
||||
'limit': rm_message_limit,
|
||||
}
|
||||
remove_opts[f]()
|
Loading…
Reference in New Issue
Block a user