blob: 87b6b3e067f0b1b6a55d724d4b465d5075d9421b [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001#pragma no_shadow, no_inherit
2#pragma strong_types,save_types,rtt_checks
3#pragma pedantic,range_check,warn_deprecated
4#pragma warn_empty_casts,warn_missing_return,warn_function_inconsistent
5
6inherit "/std/thing";
7
8#include <properties.h>
9#include <defines.h>
10
11#define BARCHIV "/d/erzmagier/boing/balance/barchives"
12
13#define BS(x) break_string(x,78,0,BS_LEAVE_MY_LFS)
14
15private varargs void print_map(mapping tmp,int short);
16
17protected void create()
18{
19 ::create();
20 SetProp(P_NAME,"Balance-Tool");
Bugfixefe25e92016-07-29 13:14:01 +020021 SetProp(P_AUTOLOADOBJ,1);
MG Mud User88f12472016-06-24 23:31:02 +020022 AddId(({"btool","balancetool","balance-tool"}));
23 SetProp(P_SHORT,"Ein Balance-Tool light");
24 SetProp(P_LONG,
25 BS("Dies ist das Balance-Tool light. Es versteht folgende Befehle:\n"
26 "- btop <n>: Zeigt den letzten genehmigten Antrag zu Top n.\n"
27 "- bsuch [-s] <str>: Sucht case-sensitiv nach str, -s bricht jeden "
28 "Eintrag nach 78 Zeichen ab.\n"
Bugfixed431842016-07-29 12:46:05 +020029 "- binhalt [-s] [uid]: Zeigt den gesamten Inhalt des Balancearchives, -s "
30 "bricht jeden Eintrag nach 78 Zeichen ab, uid filtert auf "
31 "_vollstaendige_ uids.\n\n"
MG Mud User88f12472016-06-24 23:31:02 +020032 "Es kann vorkommen, dass Eintraege der falschen UID zugeordnet sind, "
33 "oder dass die Genehmigung nicht sehr aussagekraeftig ist, in diesem "
34 "Fall bitte eine Mail an das Balanceteam schreiben."));
35 AddCmd("btop",
36 function int(string str)
37 {
38 int n;
39 if(!str || sscanf(str,"%d",n)!=1)
40 {
41 notify_fail(
42 BS("Syntax: btop <n>"));
43 return 0;
44 }
45 this_interactive()->ReceiveMsg(
46 BARCHIV->GetLightAnnounce(n),
47 MT_NOTIFICATION|MSG_BS_LEAVE_LFS);
48 return 1;
49 });
50 AddCmd("bsuch",
51 function int()
52 {
53 string str=this_interactive()->_unparsed_args();
54 if(!str || !sizeof(str))
55 {
56 notify_fail(
57 BS("Syntax: bsuch <str>"));
58 return 0;
59 }
60 int short;
61 string* arr=old_explode(str," ");
62
63 if(arr[0]=="-s")
64 {
65 short=1;
66 str=implode(arr[1..]," ");
67 }
68 mapping tmp=BARCHIV->SearchIndex(str);
69 if(!sizeof(tmp))
70 {
71 this_interactive()->ReceiveMsg(
72 "Keine Eintraege gefunden.",
73 MT_NOTIFICATION);
74 }
75 else
76 {
77 print_map(tmp,short);
78 }
79 return 1;
80 });
81 AddCmd("binhalt",
82 function int(string str)
83 {
84 int short;
Bugfixed431842016-07-29 12:46:05 +020085 string check;
86
87 mapping tmp=BARCHIV->GetIndexForWizards();
MG Mud User88f12472016-06-24 23:31:02 +020088 if(sizeof(str))
89 {
90 string* arr=old_explode(str," ");
91
92 if(arr[0]=="-s")
93 {
94 short=1;
Bugfixed431842016-07-29 12:46:05 +020095 if(sizeof(arr)>=2)
96 {
97 check=arr[1];
98 }
99 }
100 else
101 {
102 check=arr[0];
103 }
104
105 if(sizeof(check))
106 {
107 tmp=filter(tmp,
Bugfixe75df3c2016-07-29 13:11:21 +0200108 function int(int key, <int|string>* values)
Bugfixed431842016-07-29 12:46:05 +0200109 {
Bugfixe75df3c2016-07-29 13:11:21 +0200110 return values[2]==check;
Bugfixed431842016-07-29 12:46:05 +0200111 });
MG Mud User88f12472016-06-24 23:31:02 +0200112 }
113 }
114
Bugfixed431842016-07-29 12:46:05 +0200115 print_map(tmp,short);
MG Mud User88f12472016-06-24 23:31:02 +0200116 return 1;
117 });
118}
119
120private varargs void print_map(mapping tmp,int short)
121{
122 if (!mappingp(tmp))
123 {
124 this_interactive()->ReceiveMsg("Keine Daten vorhanden.\n");
125 return;
126 }
127 int* sort=sort_array(m_indices(tmp),#'>);
128 string ret="";
129 foreach(int i : sort)
130 {
131 string str=sprintf(" %4d: %s {%s} (%s)",i,tmp[i,0],tmp[i,2],
132 strftime("%d.%m.%y",tmp[i,1]));
133 if(short)
134 {
135 ret+=BS(str[0..77]);
136 }
137 else
138 {
139 ret+=BS(str);
140 }
141 }
142 this_interactive()->More(ret);
143}