Skip to content

Commit

Permalink
Make code asynchronized
Browse files Browse the repository at this point in the history
  • Loading branch information
beyondgfw committed May 21, 2020
1 parent 7da2148 commit 9bc7c21
Show file tree
Hide file tree
Showing 9 changed files with 2,320 additions and 1,444 deletions.
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The bot forwards your messages to another group.
* Support media (except voice messages).
* Reply function available.
* Anonymity: Protect the identity of the user.
* Authorised users in this group can manage the target group function, such as `/ban`, `/del`, `/kick`, etc.
* Authorised users in this group can manage the target group function, such as `/ban`, `/del`, `/grant`, `/kick`, etc.
* Use MySQL engine to mark the time, message ID and user ID.
* When the bot is mentioned in the target group, the user ID specified in the config file will also be mentioned in this group.
* Once promoted to admin, the bot can add new admins.
Expand All @@ -17,12 +17,14 @@ The bot forwards your messages to another group.

## Operating Environment

Python 3.4 and above is required
Python 3.7 and above is required

The following libraries are required:

- pyrogram (==0.11.0)
- pymysql
- pyrogram.async (==0.17.0)
- aiomysql
- aioredis
- aiofile

## Configure

Expand All @@ -44,35 +46,38 @@ The following libraries are required:

## Instruction

* Use `python3 main.py` or other command lines to run the program.
* Use `python3 repeater.py` or other command lines to run the program.
* Log in using the account you set in the `owner` field.
* If you want to authorize a certain user, you should invite the user to this group first, then use `/auth`.
* To turn off the repeater, send `/bot off` (`/boff` also available) to the target group, vice versa.
* To turn off the repeater, send `/off` to the target group, vice versa.

## Available Commands

Command | Description | Reply to the message
---|---|---
`/bon` or `/boff` | Switch on/off the bot | False
`/status` | check the user's authorization status| False
`/on` or `/off` | Switch on/off the bot | False
`/status` | check the user's authorization status | False
`/auth` | authorize to another user | True
`/ban` | put restrictions on the target user, a certain length of time can be specified (e.g. `/ban` 1m means to restrict the user for one minute) | True
`/ban` | put restrictions on the target user, a certain length of time can be specified (e.g. `/ban 1m` means to restrict the user for one minute) | True
`/kick` | remove the user from the target group | True
`/fw` | forward a message to the target group using the bot account | True
`/get` | forward the original message to this group | True
`/del` | delete the selected message in the target group | True
`/p` | gain admin access immediately for yourself in the target group | False
`/sudo` or `/su` | gain admin access immediately for yourself in the target group | False
`/promote` | authorise other users to become admins | True
`/grant` | grant specify privileges to specify user in group | False
`/pin` | pin a message in group | True
`/warn` | send a warn to user with reason | True

## Special Thanks

Special thanks to Group:J, who helped me with the translation.
Special thanks to `<unknown resource>`, who helped me with the translation.

## License

[![](https://www.gnu.org/graphics/agplv3-155x51.png)](https://www.gnu.org/licenses/agpl-3.0.txt)

Copyright (C) 2018-2019 github.com/googlehosts Group:Z
Copyright (C) 2018-2020 github.com/googlehosts Group:Z

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

Expand Down
62 changes: 48 additions & 14 deletions bot_repeater.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,69 @@
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;

-- Dumping structure for table answer_history
CREATE TABLE IF NOT EXISTS `answer_history` (
`_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`body` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Dumping structure for table auth_user
CREATE TABLE IF NOT EXISTS `auth_user` (
`id` bigint(20) NOT NULL,
`authorized` enum('Y','N') NOT NULL DEFAULT 'N',
`muted` enum('Y','N') NOT NULL DEFAULT 'N',
`whitelist` enum('Y','N') NOT NULL DEFAULT 'N',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Dumping structure for table banlist
CREATE TABLE IF NOT EXISTS `banlist` (
`id` bigint(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping structure for table exam_user_session
CREATE TABLE IF NOT EXISTS `exam_user_session` (
`user_id` int(11) NOT NULL,
`problem_id` int(11) DEFAULT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`baned` tinyint(4) NOT NULL DEFAULT '0',
`bypass` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'bypass exam',
`passed` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'passed the exam',
`unlimited` tinyint(4) NOT NULL DEFAULT '0',
`retries` int(11) NOT NULL DEFAULT '0',
`timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
`baned` tinyint(4) NOT NULL DEFAULT 0,
`bypass` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'bypass exam',
`passed` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'passed the exam',
`unlimited` tinyint(4) NOT NULL DEFAULT 0,
`retries` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Dumping structure for table msg_id
CREATE TABLE IF NOT EXISTS `msg_id` (
`msg_id` int(11) NOT NULL,
`target_id` int(11) NOT NULL DEFAULT '0',
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`user_id` bigint(20) NOT NULL DEFAULT '0',
`target_id` int(11) NOT NULL DEFAULT 0,
`timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`user_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`msg_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Dumping structure for table reasons
CREATE TABLE IF NOT EXISTS `reasons` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
`text` text COLLATE utf8mb4_unicode_ci NOT NULL,
`msg_id` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping structure for table tickets
CREATE TABLE IF NOT EXISTS `tickets` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL DEFAULT '0',
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`user_id` int(11) NOT NULL DEFAULT 0,
`timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
`hash` varchar(32) DEFAULT '',
`origin_msg` text,
`origin_msg` text DEFAULT NULL,
`section` varchar(20) DEFAULT '',
`status` varchar(10) DEFAULT '',
PRIMARY KEY (`id`),
Expand All @@ -44,9 +78,9 @@ CREATE TABLE IF NOT EXISTS `tickets_user` (
`user_id` bigint(20) NOT NULL,
`create_time` timestamp NULL DEFAULT NULL,
`last_time` timestamp NULL DEFAULT NULL,
`baned` tinyint(4) NOT NULL DEFAULT '0',
`baned` tinyint(4) NOT NULL DEFAULT 0,
`last_msg_sent` timestamp NULL DEFAULT NULL,
`step` tinyint(4) NOT NULL DEFAULT '0',
`step` tinyint(4) NOT NULL DEFAULT 0,
`section` varchar(20) DEFAULT '',
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Expand Down
15 changes: 10 additions & 5 deletions config.ini.default
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ api_id =
api_hash =
owner =
api_key =

[join_group_verify]
enable = false

[custom_service]
enable = false
custom_api_key =
emerg_contact =
help_group =

[fuduji]
target_group =
auth_user =
ignore_user =
bot_id =
fudu_group =
help_group =
replace_to_id =
whitelist =

[i18n]
language=en_US

[database]
host =
Expand Down
Loading

0 comments on commit 9bc7c21

Please sign in to comment.