Lua lobby bot

Lua lobby bot

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
MelTraX
Posts: 470
Joined: 02 Jan 2007, 16:18

Lua lobby bot

Post by MelTraX »

First of all I'm not sure if this should be in Lobby, Lua or Development..

Many have already noticed that I spent my last days (aside from the ladder development) with a lobby bot entirely written in Lua.. It's logged-in as MelBot.

I started the project because I wanted some basic ladder commands in the #league and #tourney channels but I told myself: If I'm writing a bot, why not just make it right..

I tried to resemble the Lua stuff in Spring itself as much as possible so that people who write Lua stuff for Spring can easily write Lua stuff for the lobby..

Since widget and gadget were already taken, I decided to call my widgets "melons" as it sounds cool and contains "mel" :P..

Here is an example of the melon that provides the !rank and !ladderlist commands:

Code: Select all

function melon:GetInfo()
  return {
    name   = "Ladder",
    desc   = "Provides several commands to interface with the ladder API.",
    author = "MelTraX"
  }
end



function melon:Initialize()
  bot:AddCommand("ladderlist", List, "displays a list of all ladders")
  bot:AddCommand("rank", Rank, "displays the rank of a player - params: ladderID playername")
end



function List(from, params)
  local content = http.request("http://www.spring-league.com/ladder/lobby/ladderlist.php")
  if content ~= nil then
    for word in string.gmatch(content, "([^\n]*)\n") do
      bot:Reply(word)
    end
  end
end



function Rank(from, params)
  if params == nil then
    bot:Reply("Usage: !rank <ladderID> <playerName>")
  else
    local ladder, player = SplitParameters(params)
    if ladder == nil or player == nil then
      bot:Reply("Usage: !rank <ladderID> <playerName>")
      return
    end
    local gets = "ladder=" .. ladder .. "&players[]=" .. player
    local content = http.request("http://www.spring-league.com/ladder/lobby/ranking.php?" .. gets)
    local name, rating, rank = SplitParameters(content)
    bot:Reply(name .. " is on rank " .. rank .. " with a rating of " .. rating)
  end
end
Currently available callins:

Code: Select all

Initialize()
Update(updates)
Said(channel, from, message)
GotPM(from, message)
Shutdown()
Currently available callouts:

Code: Select all

Say(conn, channel, message)
PM(to, message)
AddCommand(cmd, func, desc)
AddHelpTopic(cmd, func, desc)
RemoveCommand(cmd)
Reply(message) - only available in Command functions
To see what the bot can already do (more precisely, what you have permission to make it do), you can just PM it with "!help commands".

Stuff that's still missing are user, channel and battle callins and callouts..

If anyone is interested to write stuff for it or has suggestions what others should write for it, feel free to post here (or PM me in the lobby)..
User avatar
Neddie
Community Lead
Posts: 9406
Joined: 10 Apr 2006, 05:05

Post by Neddie »

Wow.

Uhm, can you interface between melons and other LUA creations? For example, if I had a in-game snippet of LUA which said things via text in chat, could those things trigger a rebroadcast (With time delay) through a lobby melon?

Sort of a match ticker LUA idea.

Anyway, I'll keep my eye on this, I'm stalled on my lua widgets.

EDIT: Whoops, posted too soon. I didn't notice the callin and callout plans. Good show!
MelTraX
Posts: 470
Joined: 02 Jan 2007, 16:18

Post by MelTraX »

That doesn't sound like it's possible.. I'm not sure though if there's a possibility to load the socket and http libraries in LuaUI.. Then it would be possible but I doubt it..

What is possible however is making statistics and other stuff from all the info the lobby has about games.. Which mods/maps get played, by whom, how long, ...

You have (or will have) all the information a normal user sees in the lobby and you can download whatever information you want from the web. Everything else will probably be difficult..
User avatar
Neddie
Community Lead
Posts: 9406
Joined: 10 Apr 2006, 05:05

Post by Neddie »

Be that as it may, this melon thing is pretty cool. I should make a melon based lobby bot or two for the Community Promotion deal.
MelTraX
Posts: 470
Joined: 02 Jan 2007, 16:18

Post by MelTraX »

Well, whoever is interested in actually coding a melon for the bot, please PM me in the lobby.. I'll give permissions and instructions..
Post Reply

Return to “Engine”