Skip to content

Commit

Permalink
Feat: 权限检查
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninzore committed Apr 5, 2021
1 parent 8e1fd0a commit 292503c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
11 changes: 7 additions & 4 deletions modules/plugin/bilibili.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const axios = require('axios');
const mongodb = require('mongodb').MongoClient;

const db_port = 27017;
const db_path = "mongodb://127.0.0.1:" + db_port;
const CONFIG = global.config.bilibili;
const db_path = global.config.mongoDB;
const PERMISSION = CONFIG.permission;

const option_map = {
"仅原创" : "origin",
Expand Down Expand Up @@ -521,6 +522,7 @@ function rtBiliByB23(context) {
}

function bilibiliCheck (context) {
if (!CONFIG.enable) return false;
if (/^看看.+?B站$/i.test(context.message)) {
var num = 1;
var name = "";
Expand Down Expand Up @@ -557,13 +559,15 @@ function bilibiliCheck (context) {
return true;
}
else if (/^订阅.+?B站([>>](仅转发|只看图|全部|视频更新))?/i.test(context.message)) {
if (!global.permissionCheck(context, PERMISSION)) return true;
let {groups : {name, option_nl}} = /订阅(?<name>.+?)B站([>>](?<option_nl>仅转发|只看图|视频更新|全部))?/i.exec(context.message);
console.log(`${context.group_id} ${name} 添加B站订阅`);
if (option_nl == undefined) option_nl = "仅原创"
addBiliSubscribe(context, name, option_nl);
return true;
}
else if (/^取消订阅.+?B站$/i.test(context.message)) {
if (!global.permissionCheck(context, PERMISSION)) return true;
let name = /取消订阅(.+?)B站$/i.exec(context.message)[1];
console.log(`${context.group_id} ${name} B站订阅取消`);
rmBiliSubscribe(context, name);
Expand All @@ -574,8 +578,7 @@ function bilibiliCheck (context) {
return true;
}
else if (/^清空B站订阅$/.test(context.message)) {
if (/owner|admin/.test(context.sender.role)) clearSubs(context, context.group_id);
else replyFunc(context, '您配吗?');
if (global.permissionCheck(context, ["SU", "owner"])) clearSubs(context, context.group_id);
return true;
}
else return false;
Expand Down
12 changes: 8 additions & 4 deletions modules/plugin/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ const fs = require('fs-extra');

const CONFIG = require("../../config.json");
const PROXY = CONFIG.proxy;
const DB_PORT = 27017;
const DB_PATH = "mongodb://127.0.0.1:" + DB_PORT;
const CONFIG = global.config.bilibili;
const DB_PATH = global.config.mongoDB;
const PERMISSION = CONFIG.permission;
const BEARER_TOKEN = "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA";
const MAX_SIZE = 4194304;
const OPTION_MAP = {
Expand Down Expand Up @@ -785,6 +786,7 @@ async function addSub(name, option_nl, context) {
}

function twitterAggr(context) {
if (!CONFIG.enable) return false;
if (connection && /^看看(.+?)的?((第[0-9]?[一二三四五六七八九]?条)|(上*条)|(最新))?\s?(推特|Twitter)$/i.test(context.message)) {
let num = 1;
let name = "";
Expand Down Expand Up @@ -816,6 +818,7 @@ function twitterAggr(context) {
return true;
}
else if (connection && /^订阅(推特|Twitter)https:\/\/twitter.com\/.+(\/status\/\d+)?([>>](.{2,}))?/i.test(context.message)) {
if (!global.permissionCheck(context, PERMISSION)) return true;
let name = (/status\/\d+/.test(context.message) && /\.com\/(.+)\/status/.exec(context.message)[1] ||
/\.com\/(.+)[>>]/.exec(context.message)[1]);
let option_nl = /[>>](?<option_nl>.{2,})/.exec(context.message)[1];
Expand All @@ -824,11 +827,13 @@ function twitterAggr(context) {
return true;
}
else if (connection && /^订阅.+的?(推特|Twitter)([>>](?<option_nl>.{2,}))?/i.test(context.message)) {
if (!global.permissionCheck(context, PERMISSION)) return true;
let {groups : {name, option_nl}} = /订阅(?<name>.+)的?(推特|Twitter)([>>](?<option_nl>.{2,}))?/i.exec(context.message);
addSub(name, option_nl, context);
return true;
}
else if (/^取消订阅.+的?(推特|Twitter)$/i.test(context.message)) {
if (!global.permissionCheck(context, PERMISSION)) return true;
let name = /取消订阅(.+)的?(推特|Twitter)/i.exec(context.message)[1];
unSubscribe(name, context);
return true;
Expand All @@ -838,8 +843,7 @@ function twitterAggr(context) {
return true;
}
else if (/^清空(推特|Twitter)订阅$/i.test(context.message)) {
if (/owner|admin/.test(context.sender.role)) clearSubs(context, context.group_id);
else replyFunc(context, '您配吗?');
if (global.permissionCheck(context, ["SU", "owner"])) clearSubs(context, context.group_id);
return true;
}
else return false;
Expand Down

0 comments on commit 292503c

Please sign in to comment.