| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
gh_user2bot = {} |
| 12 |
|
| 13 |
|
| 14 |
silentpings = {} |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
function gh_get_userbot_name(username) |
| 19 |
if not next(gh_user2bot) or not gh_user2bot[username] then return nil end |
| 20 |
return gh_user2bot[username].bot |
| 21 |
end |
| 22 |
|
| 23 |
function gh_get_userbot_game(username) |
| 24 |
if not next(gh_user2bot) or not gh_user2bot[username] then return nil end |
| 25 |
return gh_user2bot[username].game |
| 26 |
end |
| 27 |
|
| 28 |
function gh_get_userbot_gametype(username) |
| 29 |
if not next(gh_user2bot) or not gh_user2bot[username] then return nil end |
| 30 |
return gh_user2bot[username].gametype |
| 31 |
end |
| 32 |
|
| 33 |
|
| 34 |
function gh_find_userbot_by_game(gamename) |
| 35 |
for u,bot in pairs(gh_user2bot) do |
| 36 |
if (bot.game == gamename) then return u end |
| 37 |
end |
| 38 |
return false |
| 39 |
end |
| 40 |
|
| 41 |
function gh_set_userbot(username, botname, gamename, gametype) |
| 42 |
gh_user2bot[username] = { bot = botname, game = gamename, type = gametype, time = os.time() } |
| 43 |
end |
| 44 |
function gh_del_userbot(username) |
| 45 |
gh_user2bot[username] = nil |
| 46 |
end |
| 47 |
|
| 48 |
|
| 49 |
function gh_save_userbots(filename) |
| 50 |
table.save(gh_user2bot, filename) |
| 51 |
return true |
| 52 |
end |
| 53 |
|
| 54 |
function gh_load_userbots(filename) |
| 55 |
gh_user2bot = table.load(filename) |
| 56 |
|
| 57 |
|
| 58 |
if next(gh_user2bot) then |
| 59 |
TRACE("Users assigned to bots:") |
| 60 |
for u,bot in pairs(gh_user2bot) do |
| 61 |
TRACE(u..": "..bot.bot.." ("..bot.game..", "..bot.time..")") |
| 62 |
end |
| 63 |
end |
| 64 |
end |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
function gh_set_silentflag(username) |
| 71 |
table.insert(silentpings, account.name) |
| 72 |
end |
| 73 |
|
| 74 |
function gh_get_silentflag(username) |
| 75 |
for k,v in pairs(silentpings) do |
| 76 |
if v == username then |
| 77 |
table.remove(silentpings, k) |
| 78 |
return true |
| 79 |
end |
| 80 |
end |
| 81 |
return false |
| 82 |
end |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
function gh_directory() |
| 87 |
return config.scriptdir .. "/ghost" |
| 88 |
end |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
function gh_is_owner(account) |
| 94 |
|
| 95 |
if not account.game_id then return false end |
| 96 |
|
| 97 |
local game = game_get_by_id(account.game_id) |
| 98 |
|
| 99 |
if not game.owner == gh_get_userbot_name(account.name) then return false end |
| 100 |
|
| 101 |
return true |
| 102 |
end |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
function gh_is_bot(username) |
| 109 |
for i,bot in pairs(config.ghost_bots) do |
| 110 |
if string.lower(bot) == string.lower(username) then return true end |
| 111 |
end |
| 112 |
return false |
| 113 |
end |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
function gh_message_send(botname, text) |
| 118 |
|
| 119 |
api.message_send_text(botname, message_type_whisper, nil, text) |
| 120 |
end |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
function gh_select_bot(username) |
| 125 |
local pings = account_get_botping(username) |
| 126 |
local botname = nil |
| 127 |
|
| 128 |
|
| 129 |
for i,bot in pairs(config.ghost_bots) do |
| 130 |
local is_found = false |
| 131 |
for k,v in pairs(pings) do |
| 132 |
if bot == v.bot then is_found = true end |
| 133 |
end |
| 134 |
|
| 135 |
if not is_found then |
| 136 |
botname = bot |
| 137 |
end |
| 138 |
end |
| 139 |
|
| 140 |
|
| 141 |
if not botname then |
| 142 |
|
| 143 |
botname = pings[1].bot |
| 144 |
end |
| 145 |
|
| 146 |
local botacc = api.account_get_by_name(botname) |
| 147 |
|
| 148 |
|
| 149 |
if botacc.online == "false" then |
| 150 |
botname = nil |
| 151 |
for i,bot in pairs(config.ghost_bots) do |
| 152 |
botacc = api.account_get_by_name(bot) |
| 153 |
if botacc.online == "true" then return bot end |
| 154 |
end |
| 155 |
end |
| 156 |
|
| 157 |
return botname |
| 158 |
end |
| 159 |
|
| 160 |
|