Merge branch 'master' of https://github.com/soend/telegram-bot into soend-master

Conflicts:
	bot/bot.lua
This commit is contained in:
yago 2015-04-12 22:08:56 +02:00
commit 0438abeee3
3 changed files with 72 additions and 2 deletions

View File

@ -42,6 +42,12 @@ function msg_valid(msg)
print("Not valid, readed")
return false
end
if is_disabled(msg) then
print("Disabled channel")
return false
end
return true
end
@ -158,6 +164,7 @@ function create_config( )
"location",
"media",
"plugins",
"channels",
"set",
"stats",
"time",
@ -165,7 +172,8 @@ function create_config( )
"weather",
"xkcd",
"youtube" },
sudo_users = {our_id}
sudo_users = {our_id},
disabled_channels = {}
}
serialize_to_file(config, './data/config.lua')
print ('saved config into ./data/config.lua')

View File

@ -177,6 +177,20 @@ function is_sudo(msg)
return var
end
function is_disabled(msg)
local var = false
if msg.text == "!channel enable" then
return var
end
-- Check users id in config
for v,channel in pairs(_config.disabled_channels) do
if channel == msg.to.id then
var = true
end
end
return var
end
-- Returns the name of the sender
function get_name(msg)
local name = msg.from.first_name
@ -446,4 +460,4 @@ function match_pattern(pattern, text)
return matches
end
-- nil
end
end

48
plugins/channels.lua Normal file
View File

@ -0,0 +1,48 @@
function enable_channel( channel_id, channel_name )
-- Add to the config table
table.remove(_config.disabled_channels, get_index(channel_id))
save_config()
return "Channel "..channel_name.." enabled"
end
function disable_channel( channel_id, channel_name )
-- Disable
table.insert(_config.disabled_channels, channel_id)
save_config( )
return "Channel "..channel_name.." disabled"
end
function get_index( channel_id )
for k,v in pairs(_config.disabled_channels) do
if channel_id == v then
return k
end
end
-- If not found
return false
end
function run(msg, matches)
-- Enable a channel
if matches[1] == 'enable' then
print("enable: "..msg.to.id)
return enable_channel(msg.to.id, msg.to.title)
end
-- Disable a channel
if matches[1] == 'disable' then
print("disable: "..msg.to.id)
return disable_channel(msg.to.id, msg.to.title)
end
end
return {
description = "Plugin to manage channels. Enable or disable channel.",
usage = {
"!channel enable: enable current channel",
"!channel disable: disable current channel" },
patterns = {
"^!channel? (enable)",
"^!channel? (disable)" },
run = run,
privileged = true
}