Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
start building botway lua client package (botway-lua)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Jul 4, 2022
1 parent 363d8d7 commit 5fcb915
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/botway-lua/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Abdfn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 31 additions & 0 deletions packages/botway-lua/botway-lua-1.0-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package = "botway-lua"
version = "1.0-1"

source = {
url = "git+https://github.com/Mehgugs/lacord.git"
}

description = {
summary = "Lua client package for Botway.",
homepage = "https://github.com/abdfnx/botway",
license = "MIT",
maintainer = "Abdfnx",
detailed = [[
Lua client package for Botway.
After creating a new lua botway project, you need to use your tokens to connect with your bot.
]]
}

dependencies = {
"lua >= 5.2",
"lyaml",
"path",
"lunajson"
}

build = {
type = "builtin",
modules = {
["botway-lua"] = "src/botway.lua"
}
}
40 changes: 40 additions & 0 deletions packages/botway-lua/src/botway.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
local yaml = require "lyaml"
local path = require "path"
local json = require "lunajson"

local BotwayConfigFile = io.open(path.join(path.user_home(), ".botway", "botway.json"))

if BotwayConfigFile == nil then
print("ERROR: Botway config file not found")
return
end

local BotwayConfig = json.decode(BotwayConfigFile:read("a"))
local BotConfig = io.open(".botway.yaml", "r")

if BotConfig == nil then
print("ERROR: Bot config file not found")
return
end

local Botway = {}

function Botway.GetBotInfo(value)
local config = yaml.load(BotConfig:read("a"))

return config["bot"][value]
end

function Botway.GetToken()
return BotwayConfig["botway"]["bots"][Botway.GetBotInfo("name")]["bot_token"]
end

function Botway.GetAppId()
return BotwayConfig["botway"]["bots"][Botway.GetBotInfo("name")]["bot_app_id"]
end

function Botway.GetGuildId(serverName)
return BotwayConfig["botway"]["bots"][Botway.GetBotInfo("name")]["guilds"][serverName]["server_id"]
end

return Botway

0 comments on commit 5fcb915

Please sign in to comment.