Skip to content

TRIGONIM/ggram

main
Switch branches/tags
Code

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
lua
 
 
 
 
 
 
 
 
 
 

ggram Telegram Bot Framework

NEED TRANSLATORS. Please, make pull requests if you wanna help. Temporarily I recommend deepl to translate this page

苤郋郱迡訄赲訄邿迮 Telegram 訇郋郋赲 郅訇郋邿 郅郋迠郇郋邽 郇訄 Lua

local bot = ggram("token")

bot.enable_polling() -- enables getUpdates loop

bot.command("start", function(ctx)
	ctx.reply.text("Hello @" .. ctx.from.username)
end)

郋郈郋郅郇邽迮郅郇迮 郈邽邾迮 邾郋迠郇郋 郇訄邿邽 赲 /examples


Demo

迡迮 (郕郅邽郕) 郋郈訇郅邽郕郋赲訄郇 郅郕邽 郇訄 訄訇郋訄邽迮 訇郋, 訄 訄郕迠迮 邾郇郋迠迮赲郋 邽迡迮邿, 郕郋郋迮 邾郋迠郇郋 迮訄郅邽郱郋赲訄 郈邽 郈郋邾郋邽 郋迣郋 迮邿邾赲郋郕訄 迡郅 赲郋迮迣郋 Garry's Mod 迮赲迮訄 邽 郇迮 郋郅郕郋. 郋郱邾郋迠郇郋邽 郈訄郕邽迮郕邽 訇迮郱迣訄郇邽郇.


Features

  • 郋迠迮 訄訇郋訄 郕訄郕 郇訄 邽郋邾 Lua, 訄郕 邽 郇訄 Garry's Mod 迮赲迮迮
  • 迮訇迮 郇邽郕訄郕邽 郋郋郇郇邽 .dll 邽郅邽 WEB 郈郋郅郋迮郕
  • 迮郇 邾邽郇邽邾訄郅邽邽郇邿 邽 郅迮迣郕郋 訄邽迮邾邿
  • 訄迠迮 赲 郅訄迮 郋訄赲訄郇邽 郋 Telegram API 郅迮迣郕郋 赲郱赲訄 郇郋赲迮 邾迮郋迡
  • 郋郱邾郋迠郇郋 郋郈訄赲郕邽 訄郇邽邾訄邽邿, 迡郋郕邾迮郇郋赲, 邽郱郋訇訄迠迮郇邽邿
  • 苤郋郱迡訄郇 迮郋邾 邾郇郋迣郋郅迮郇郋迣郋 郋郈訄 郋郱迡訄郇邽 訇郋郋赲
  • 迠邽 郈訄訄迡邽迣邾郋邿 郇郕邽郋郇訄郅郇郋迣郋 郈郋迣訄邾邾邽郋赲訄郇邽

Installation

Linux / Mac

Install luarocks (package manager like apt but for lua)

sudo apt install luarocks # linux
# or
brew install luarocks # mac

Install ggram

luarocks install ggram # latest release
# or
luarocks install --server=https://luarocks.org/dev ggram # just latest

Make and run bot:

  1. Create bot.lua file. You can choose any name for the file
  2. Paste the contents of /examples/echo.lua into the file
  3. Run file with lua bot.lua

If any error was occur, check the troubleshooting part below

Garry's Mod

  1. 苤郕訄訄邿迮 ggram 郋迣郋 迮郈郋郱邽郋邽 邽 訄郇郋赲邽迮 赲 /addons/ggram
  2. 苤郋郱迡訄邿迮 訄邿郅 /addons/ggram_bots/lua/ggram/bots/anyname/_init.lua
  3. 訄郈郋郅郇邽迮 迮迣郋 郋迡迮迠邽邾邾 迡迮邾郋郇訄邽赲郇郋迣郋 訇郋訄 邽郱 郈訄郈郕邽 /examples, 郕訄郱訄赲 郋郕迮郇 @BotFather

Docs


Development tips and tricks

迮 訄郕訄郅郇郋 迡郅 Garry's Mod

launcher.lua

郅邽 赲 郈郅訄郇邽迮迮 郋郱迡訄 郇迮郕郋郅郕郋 訇郋郋赲, 郋 赲邾迮郋 郋迡迮郅郇 訄邿郅郋赲 郈郋迡 郕訄迠迡邿 訇郋 邾郋迠郇郋 邽郈郋郅郱郋赲訄 郋迡邽郇 訄邿郅, 郕郋郋邿 郱訄郈邽 赲迮 郋訄郅郇迮 訇郋 郈邽邾迮郇郋 郈郋 訄郕郋邿 迮邾迮:

-- 郈邽郋郇訄郅郇郋, 郈 郕 郈訄郈郕迮  邾郋迡郅邾邽
package.path = package.path ..
	";/path/?.lua" ..
	";/path/?/init.lua"

-- 邾郈郋 ggram
require("ggram.core")

-- 苤郈邽郋郕 訄邿郅郋赲  郕郋迡郋邾 訇郋郋赲
local bots = {"bot_file1", "bot_file2"}
for _,bot_name in ipairs(bots) do
	assert(pcall(require, bot_name))
	print(bot_name .. " loaded")
end

-- 訄郈郕訄迮邾 訄邾訄郇郕
ggram.idle()

Only one polling server

郅 迮, 郕郋 郋迮 訄訇郋訄 郕迮邿 訇郋郋赲 訇迮郱 郅邽郇郋迣郋 赲迮訇 迮赲迮訄

迡迮郅訄郅 邾邽郕郋迮赲邽, 郕郋郋邿 郈邽郇邽邾訄迮 赲迮訇郕邽 郋 訄郱郇 迮赲邽郋赲, 訄 訄邾 赲郈訄迮 赲 郕訄迮赲迮 polling 迮赲迮訄, 郈郋迡郋訇郇郋 郕訄郕 訄訇郋訄迮 getUpdates 赲 Telegram. 迮 訇郋 郋郈訄赲郅 迮邾 郋訇郇郋赲郅迮郇邽, 郱訄迮邾 HTTP GET 郱訄郈郋郋邾 郈郋郅訄 邽 赲 郋迡郇郋邾 邾迮迮.

郅 訄訇郋 邽邾 迮赲邽郋邾 郇訄郈邽訄郅 郇迮訇郋郅郋邿 迮邿邾赲郋郕 邽 迮郅邽 迡郅 赲訄 郋 邽郇迮迮郇郋, 郋 邾郋迣 郋郈訇郅邽郕郋赲訄 迣訄邿迡, 郕訄郕 迮迣郋 郈邽邾迮郇邽.

Debugging

VSCode 邽邾迮迮 郋迮郇 郕郋邿 赲郋迮郇郇邿 迡迮訇訄迣迣迮. 郅邽 訄郇郋赲邽 迡郅 郇迮迣郋 Lua Debug 郈郅訄迣邽郇, 郋 迮迣郋 郈郋邾郋 迡郋訇郇迮迮 郱訄郇邽邾訄 訄郱訄訇郋郕郋邿


Troubleshooting

郋郈邽迮 郈邽 邽郈郋郅郱郋赲訄郇邽邽 ggram 赲 邽迮邾迮, 訄 郇迮 赲 郈迮迡迮郅訄 Garry's Mod

Lua versioning problems

郅邽 郇訄 郋迮 訄郇郋赲郅迮郇郋 郇迮郕郋郅郕郋 赲迮邽邿 Lua, 郋 郋郋訇迮郇郇郋 訄郕訄郅郇郋 迡郅 Mac, 郋 迮 赲迮郋郇郋 郈郋訇郅迮邾 邽郱-郱訄 郋迣郋, 郋 luarocks 邽郈郋郅郱迮 赲迮邽 Lua 郇迮 迠迮, 郋 邽郈郋郅郱迮 赲 邽迮邾迮 郈郋 邾郋郅訄郇邽.

ggram 迮邽郋赲訄郅 郇訄 lua 5.3.6 邽 邾郋迠迮 郇迮 訄訇郋訄 訇郋郅迮迮 赲迮迠邽邾邽 赲迮邽邾邽 Lua

郋郋邾 赲 郅訄 郈郋訇郅迮邾 赲迮邽邾邽, 迡郋訄郋郇郋 赲郈郋郅郇 赲迮 luarocks 郕郋邾訄郇迡 c 郈訄訄邾迮郋邾 --lua-dir=$(brew --prefix)/opt/lua@5.3, 郇訄郈邽邾迮 luarocks --lua-dir=$(brew --prefix)/opt/lua@5.3 install ggram

邽邾迮 郕訄郱訄郇 迡郅 Mac, 郇訄 Linux lua 訇迡迮 赲 迡迣郋邿 郈訄郈郕迮 邽郅邽 訄郇郋赲郅迮郇郇訄 赲迮邽 luarocks 邾郋迠迮 赲郋赲迮 郇迮 郈郋迡迡迮迠邽赲訄 訄郕郋邿 郈訄訄邾迮 (郋迡迡迮迠郕訄 迡郋訇訄赲郅迮郇訄 赲 luarocks 3.0.1)

訄 郋迡郇郋邾 linux 郋迮 邾迮郇 luarocks 邽郈郋郅郱迮 lua 5.1 邽 郇迮郋訇郋迡邽邾郋邽 赲 訄郕郋邾 郈訄訄邾迮迮 郇迮 訇郅郋

$ luarocks install ggram

Error: Your user does not have write permissions in /usr/local/lib/luarocks/rocks you may want to run as a privileged user or use your local tree with --local.

Just add --local argument to the command:

$ luarocks install --local ggram

$ luarocks install luasec

luarocks install luasec No file openssl/ssl.h

You need to install openssl

  • Ubuntu: apt install libssl-dev, then retry command
  • Mac: brew install openssl, then luarocks install luasec OPENSSL_DIR=/opt/homebrew/opt/openssl@3

Problems with luasocket installation

Ran into this on Ubuntu 20.04. I did not record the error itself

luarocks install luasocket
mkdir lua-build && cd lua-build
curl -R -O http://www.lua.org/ftp/lua-5.3.6.tar.gz && tar -zxf lua-5.3.6.tar.gz && cd lua-5.3.6
make linux test # You may need to sudo apt install make
make install

$ lua bot.lua

lua: bot.lua:5: module 'ggram.core' not found

郋邽郋迡邽, 迮郅邽 luarocks install 赲郈郋郅郇郅 郈訄訄邾迮郋邾 --local. 郋邾 郅訄迮 lua 郕邽郈 郇迠郇郋 郋郋訇邽, 迣迡迮 邽郕訄 邾郋迡郅邽. 郅 郋迣郋 赲迮 訄邿郅訄 訇郋郋邾 郇迠郇郋 迡郋訇訄赲邽:

-- /home/ubuntu/.luarocks/share/lua/5.1
-- /\ 郇迠郇郋 郱訄邾迮郇邽 郇訄 郈 郕 郈訄郈郕迮  邾郋迡郅邾邽
-- 苺郱郇訄 邾郋迠郇郋 赲郈郋郅郇邽赲 luarocks show ggram
package.path = package.path
	.. ";/home/ubuntu/.luarocks/share/lua/5.1/?.lua"
	.. ";/home/ubuntu/.luarocks/share/lua/5.1/?/init.lua"

Other

If any of these problems are out of date or if you encounter others, then create an Issue, in which you need to specify the system version, the version of lua -v, and step by step the actions you have taken


郅邽 郋訄郅邽 赲郋郈郋, 赲 邾郋迠迮迮 郱訄迡訄 邽 赲 Telegram @amd_nick 邽郅邽 郋郱迡訄 Issue