Skip to content

Commit

Permalink
Merge pull request mullwar#127 from YouTwitFaceTG/master
Browse files Browse the repository at this point in the history
Update permissions.js and ignoreMessagesBeforeStart.js
  • Loading branch information
mullwar authored Mar 29, 2018
2 parents 33dfddf + 50e6591 commit 743f8a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
19 changes: 14 additions & 5 deletions plugins/ignoreMessagesBeforeStart.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
var startDate;
const startDate = {};

module.exports = {

id: 'ignoreMessagesBeforeStart',

plugin(bot) {
defaultConfig: {
start: true
},

bot.on(['start', '/start'], () => {
startDate = Date.now();
plugin(bot, config) {

bot.on([config.start ? 'start', '/start' : 'start'], (msg) => {
let userId = 'main_bot';
if (msg && msg.from) {
userId = msg.from.id;
}
startDate[userId] = Date.now();
});

bot.mod('message', (data) => {
if (data.message.date*1000 < startDate) {
const { date, from } = data.message;
if (date * 1000 < startDate[from.id] || date * 1000 < startDate.main_bot) {
data.message = {};
}

Expand Down
19 changes: 14 additions & 5 deletions plugins/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@ module.exports = {

id: 'permissions',
defaultConfig: {
allowedUserNames: [],
allowedUserIds: [],
allowedChannels: [],
message: '⛔ you are not authorized'
},

plugin(bot, pluginConfig) {

bot.mod('message', (data) => {
const userId = data.message.from.id;
if (pluginConfig.allowedUserNames.indexOf(data.message.from.username) < 0) {
data.message = {};
bot.sendMessage(userId, pluginConfig.message);
if (data.message.chat.type === 'channel') {
const chatId = data.message.chat.id;
if (!pluginConfig.allowedChannels.includes(chatId)) {
data.message = {};
bot.sendMessage(chatId, pluginConfig.message);
}
} else {
const userId = data.message.from.id;
if (!pluginConfig.allowedUserIds.includes(userId)) {
data.message = {};
bot.sendMessage(userId, pluginConfig.message);
}
}

return data;
Expand Down

0 comments on commit 743f8a1

Please sign in to comment.