Skip to content

Commit

Permalink
Jack version 1 !
Browse files Browse the repository at this point in the history
  • Loading branch information
Imandaneshi committed Apr 8, 2016
1 parent 10c9bc5 commit 76e392c
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 14 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Jack
# Jack

Multi purpose telegram bot written in MoonScript/lua and licenced under the GNU General Public License.

Expand All @@ -9,6 +9,7 @@ Multi purpose telegram bot written in MoonScript/lua and licenced under the GNU
Table of Contents

* [Setup](#setup)
* [Ranks](#ranks)
* [Telegram Cli](#telegram-cli)
* [Database](#database)
* [Plugins](#plugins)
Expand All @@ -17,7 +18,7 @@ Table of Contents
* [Collaborators](#collaborators)
* [Other projects](#other-projects)

#Setup
# Setup

Clone Jack !

Expand Down Expand Up @@ -58,13 +59,17 @@ chmod +x run.sh

### options

*1 - No output*
Use `./run.sh --help` for available options

`--no-output`

>./run.sh --no-output
# Ranks

Bot wont print msgs in this mod
Ranks | Permissions |
------ | ---------------- |
Admin | Has access to everything
premium | Has access to premium feature
normal user | Has access to public feature
blacklisted | Bot will ignore blacklisted users

# Telegram cli

Expand Down Expand Up @@ -103,7 +108,7 @@ Few examples

[Telegram CLI Commands](https://github.com/vysheng/tg/wiki/Telegram-CLI-Commands)

#Database
# Database

Jack uses redis as database

Expand Down Expand Up @@ -917,6 +922,8 @@ Join our development group by sending /join 1047524697 to [@TeleSeed](https://te

[Yago](https://github.com/yagop)

[Flippylosaurus](https://telegram.me/Flippylosaurus)



# Collaborators
Expand Down
42 changes: 41 additions & 1 deletion jackbot.moon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export socket = require "socket"
export JSON = require "cjson"
export colors = require 'ansicolors'
export config = moonscript.loadfile "config.moon"
http.TIMEOUT = 5
https.TIMEOUT = 5
utilities = moonscript.loadfile "utilities.moon",implicitly_return_root:true
utilities!
export redis = (Redis @).client
Expand Down Expand Up @@ -80,6 +82,42 @@ export msg_processor = (msg) ->
if msg.text
if msg.text\match '^[/]'
msg.text = msg.text\gsub "@#{bot_username}",""--Remove username
--Msg filter
if admin_only!
unless is_admin(msg)
return
msg.text = "###photo" if msg.photo

msg.text = "###audio" if msg.audio

msg.text = "###document" if msg.document

msg.text = "###sticker" if msg.sticker

msg.text = "###video" if msg.video

msg.text = "###voice" if msg.voice

msg.text = "###contact" if msg.contact

msg.text = "###location" if msg.location

msg.text = "###new_chat_participant" if msg.new_chat_participant

msg.text = "###left_chat_participant" if msg.left_chat_participant

msg.text = "###new_chat_title" if msg.new_chat_title

msg.text = "###new_chat_photo" if msg.new_chat_photo

msg.text = "###delete_chat_photo" if msg.delete_chat_photo

msg.text = "###group_chat_created" if msg.group_chat_created

msg.text = "###supergroup_chat_created" if msg.supergroup_chat_created

msg.text = "###migrate" if msg.migrate_to_chat_id

msg_text = msg.text or ""
--User changed chat name
msg_text = "changed group name to > #{msg.new_chat_title}" if msg.new_chat_title
Expand Down Expand Up @@ -249,10 +287,12 @@ export inline_query_received = (inline) ->


bot_run!--Load the bot
print colors("%{red}\nNo output mode enabled . I wont print messages\n%{reset}") if no_output!
print colors("%{red}\nNo output mode enabled. I wont print messages\n%{reset}") if no_output!
print colors("%{red}\nAdmin mode enabled.\n%{reset}") if admin_only!
while is_running--A loop for getting messages

if last_cron < os.time() - 10--cron thing
export last_cron = os.time()
for i,v in pairs plugins
if (v @)
if (v @).cron
Expand Down
51 changes: 50 additions & 1 deletion plugins/admin.moon
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
obtain_user_info = (user_id) ->
first_name = false
last_name = false
username = false
info = redis\hgetall "bot:users:#{user_id}"
if info
if info.first_name
first_name = info.first_name
if info.last_name
last_name = info.last_name
if info.username
username = info.username
text = ""
if first_name
text ..= "#{first_name} "
if last_name
text ..= "#{last_name} "
text ..= "#{user_id} "
if username
text ..= "@#{username}"
text ..= "\n"
return text

premium_list = (msg) ->
text = ""
users = redis\smembers "bot:premium:users"
for k,v in pairs(users)
text ..= "#{obtain_user_info v}"
return text

spairs = (t, order) ->
-- collect the keys
keys = {}
Expand Down Expand Up @@ -98,7 +128,23 @@ run = (msg,matches) ->
elseif matches[4] == "true" then
redis\set "bot:plugin_disabled_on_chat:#{matches[2]}:#{matches[3]}", true
return "*Plugin* `#{matches[2]} `disabled on `#{matches[3]}`"
return
if matches[1] == "premium"
if matches[2]
if matches[2] == "list"
return premium_list!
user_id = ""
if msg.reply_to_message
user_id = msg.reply_to_message.from.id
elseif matches[2]
user_id = matches[2]

is_premium = redis\sismember("bot:premium:users", user_id)
if is_premium
redis\srem("bot:premium:users", user_id)
return "`User #{user_id} removed from premium list`"
else
redis\sadd("bot:premium:users", user_id)
return "`User #{user_id} Added to premium list`"



Expand All @@ -107,7 +153,10 @@ patterns = {
"^[!#/](plugins) ([^%s]+) (.+) (true)$"
"^[!#/](plugins) ([^%s]+) (.+) (false)$"
"^[!#/](blacklist) (%d+)$"
"^[!#/](premium) (%d+)$"
"^[!#/](premium) (list)$"
"^[!#/](blacklist)$"
"^[!#/](premium)$"
"^[!#/](bc) ([^%s]+) (.*)$"
"^[!#/](broadcast) +(.+)$"
"^[!#/](bot)$"
Expand Down
50 changes: 46 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
while true; do
moon jackbot.moon "${@}"
sleep 10s
done
ver="1.0"
if [ "$1" = "--help" ]; then
echo -e "
\033[31;47mJack Telegram Bot\033[0m
\033[5mV $ver\033[0m
--no-outpot Bot won't print incoming msgs
--admin-mode Only listen to admins !
--update Sync bot with master repo
--about About bot
--help Prints this msg
"

elif [ "$1" = "--about" ]; then
echo -e "
\033[31;47mJack Telegram Bot\033[0m
By Iman Daneshi
\033[5mV $ver\033[0m
A multi purpose Telegram bot written in MoonScript !
Website: jack.seedteam.org
"
elif [ "$1" = "--Update" ]; then
git pull
else
echo -e "
\033[31;47mJack Telegram Bot\033[0m
By Iman Daneshi
\033[5mV $ver\033[0m
"
while true; do
moon jackbot.moon "${@}"
sleep 10s
done
fi
21 changes: 20 additions & 1 deletion utilities.moon
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,25 @@ export up_the_first = (word) ->
export no_output = ->
if #arg >= 1
for k,v in pairs arg
if v == "--no-output"
if v\lower! == "--no-output"
return true
return false

export admin_only = ->
if #arg >= 1
for k,v in pairs arg
if v\lower! == "--admin-mode"
return true
return false

export is_premium = (msg) ->
if is_admin(msg)
return true
redis = (Redis @).client
users = redis\smembers "bot:premium:users"
for k,v in pairs(users)
if msg.from.id == tonumber(v)
return true
if msg.chat.id == tonumber(v)
return true
return false

0 comments on commit 76e392c

Please sign in to comment.