summaryrefslogtreecommitdiffstats
blob: 897b89cf5dcadcbe70f2f45a33781a133697f179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
agendas = {}
currents = {}

function full_agenda(from)
   fullagenda = {}
   fullagenda[1] = "Roll call"
   fullagenda[2] = "Agenda bashing"
   for i, v in ipairs(agendas[from]) do
      table.insert(fullagenda, v)
   end
   table.insert(fullagenda, "Date of next meeting")
   table.insert(fullagenda, "Any other business")
   return fullagenda
end

function agenda_full_command(command, params, message)
   from = message['frombare']
   ensure_loaded(from)
   agenda = agendas[from]
   fullagenda = full_agenda(from)
   reply = ""
   for i, v in ipairs(fullagenda) do
      reply = reply..i..") "..v.."\n"
   end
   reply = reply.."Fini"
   swiftob_reply_to(message, reply)
end

function agenda_append_command(command, params, message)
   from = message['frombare']
   agenda_append(from, params)
   agenda_save(from)
   swiftob_reply_to(message, "Done.")
end

function agenda_up_command(command, params, message)
   from = message['frombare']
   ensure_loaded(from)
   up = tonumber(params)
   if up == nil then up = 1 end
   currents[from] = currents[from] + up
   if currents[from] <= 0 then currents[from] = 1 end
   item = full_agenda(from)[currents[from]]
   if item == nil then item = "Fini." end
   reply = currents[from]..") "..item
   swiftob_reply_to(message, reply)
end


function agenda_clear_command(command, params, message)
   from = message['frombare']
   agendas[from] = {}
   agenda_save(from)
   swiftob_reply_to(message, "Done.")
end

function agenda_save(from)
   agenda = agendas[from]
   swiftob_store_setting("count@@@"..from, #agenda)
   for i, v in ipairs(agenda) do
      swiftob_store_setting(i.."@@@"..from, v)
   end
end

function ensure_loaded(from)
   if agendas[from] == nil then
      agenda_load(from)
   end
end

function agenda_load(from)
   agendas[from] = {}
   currents[from] = 0
   num_items = tonumber(swiftob_get_setting("count@@@"..from))
   if num_items == nil then num_items = 0 end
   for i = 1, num_items do
      agenda_append(from, swiftob_get_setting(i.."@@@"..from))
   end
end

function agenda_append(from, item)
   ensure_loaded(from)
   agenda = agendas[from]
   table.insert(agenda, item)
   agendas[from] = agenda
end

swiftob_register_command("agenda", "Anyone", "print the full agenda", agenda_full_command)
swiftob_register_command("agendaappend", "Owner", "append an item to the agenda", agenda_append_command)
swiftob_register_command("agendaclear", "Owner", "clear the agenda", agenda_clear_command)
swiftob_register_command("agendaup", "Owner", "Moves the current counter by n, and returns the current agenda item", agenda_up_command)