blob: 649dda8bd187df5e0f51540916b80f527c1173c3 [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
Zesstrad39f73d2018-11-09 00:01:15 +01006inherit "/std/secure_thing";
MG Mud User88f12472016-06-24 23:31:02 +02007
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)
Arathorn32fe1792019-09-15 14:40:47 +020014#define BSI(x) break_string(x, 78, y, BS_LEAVE_MY_LFS|BS_INDENT_ONCE)
MG Mud User88f12472016-06-24 23:31:02 +020015
16private varargs void print_map(mapping tmp,int short);
17
18protected void create()
19{
20 ::create();
21 SetProp(P_NAME,"Balance-Tool");
Bugfixefe25e92016-07-29 13:14:01 +020022 SetProp(P_AUTOLOADOBJ,1);
Arathorn82058962018-01-05 23:42:05 +010023 SetProp(P_NODROP,1);
24 SetProp(P_NEVERDROP,1);
MG Mud User88f12472016-06-24 23:31:02 +020025 AddId(({"btool","balancetool","balance-tool"}));
26 SetProp(P_SHORT,"Ein Balance-Tool light");
27 SetProp(P_LONG,
Arathorn32fe1792019-09-15 14:40:47 +020028 BS("Dies ist das Balance-Tool light. Es versteht folgende Befehle:")+
29 BSI("btop <n>:\nZeigt den letzten genehmigten Antrag zu Top n.","- ")+
30 BSI("bsuch [-s] <str>:\nSucht case-sensitiv nach str, -s bricht jeden "
31 "Eintrag nach 78 Zeichen ab. str darf eine RegExp sein.", "- ")+
32 BSI("binhalt [-s] [uid]:\nZeigt den gesamten Inhalt des Balancearchives, "
33 "-s bricht jeden Eintrag nach 78 Zeichen ab, uid filtert auf "
34 "_vollstaendige_ uids.", "- ")+"\n"+
35 BS("Es kann vorkommen, dass Eintraege der falschen UID zugeordnet sind, "
MG Mud User88f12472016-06-24 23:31:02 +020036 "oder dass die Genehmigung nicht sehr aussagekraeftig ist, in diesem "
37 "Fall bitte eine Mail an das Balanceteam schreiben."));
38 AddCmd("btop",
39 function int(string str)
40 {
41 int n;
42 if(!str || sscanf(str,"%d",n)!=1)
43 {
44 notify_fail(
45 BS("Syntax: btop <n>"));
46 return 0;
47 }
48 this_interactive()->ReceiveMsg(
49 BARCHIV->GetLightAnnounce(n),
50 MT_NOTIFICATION|MSG_BS_LEAVE_LFS);
51 return 1;
52 });
53 AddCmd("bsuch",
54 function int()
55 {
56 string str=this_interactive()->_unparsed_args();
57 if(!str || !sizeof(str))
58 {
59 notify_fail(
60 BS("Syntax: bsuch <str>"));
61 return 0;
62 }
63 int short;
64 string* arr=old_explode(str," ");
65
66 if(arr[0]=="-s")
67 {
68 short=1;
69 str=implode(arr[1..]," ");
70 }
71 mapping tmp=BARCHIV->SearchIndex(str);
72 if(!sizeof(tmp))
73 {
74 this_interactive()->ReceiveMsg(
75 "Keine Eintraege gefunden.",
76 MT_NOTIFICATION);
77 }
78 else
79 {
80 print_map(tmp,short);
81 }
82 return 1;
83 });
84 AddCmd("binhalt",
85 function int(string str)
86 {
87 int short;
Bugfixed431842016-07-29 12:46:05 +020088 string check;
89
90 mapping tmp=BARCHIV->GetIndexForWizards();
MG Mud User88f12472016-06-24 23:31:02 +020091 if(sizeof(str))
92 {
93 string* arr=old_explode(str," ");
94
95 if(arr[0]=="-s")
96 {
97 short=1;
Bugfixed431842016-07-29 12:46:05 +020098 if(sizeof(arr)>=2)
99 {
100 check=arr[1];
101 }
102 }
103 else
104 {
105 check=arr[0];
106 }
107
108 if(sizeof(check))
109 {
110 tmp=filter(tmp,
Bugfixe75df3c2016-07-29 13:11:21 +0200111 function int(int key, <int|string>* values)
Bugfixed431842016-07-29 12:46:05 +0200112 {
Bugfixe75df3c2016-07-29 13:11:21 +0200113 return values[2]==check;
Bugfixed431842016-07-29 12:46:05 +0200114 });
MG Mud User88f12472016-06-24 23:31:02 +0200115 }
116 }
117
Bugfixed431842016-07-29 12:46:05 +0200118 print_map(tmp,short);
MG Mud User88f12472016-06-24 23:31:02 +0200119 return 1;
120 });
121}
122
123private varargs void print_map(mapping tmp,int short)
124{
125 if (!mappingp(tmp))
126 {
127 this_interactive()->ReceiveMsg("Keine Daten vorhanden.\n");
128 return;
129 }
130 int* sort=sort_array(m_indices(tmp),#'>);
131 string ret="";
132 foreach(int i : sort)
133 {
134 string str=sprintf(" %4d: %s {%s} (%s)",i,tmp[i,0],tmp[i,2],
135 strftime("%d.%m.%y",tmp[i,1]));
136 if(short)
137 {
138 ret+=BS(str[0..77]);
139 }
140 else
141 {
142 ret+=BS(str);
143 }
144 }
145 this_interactive()->More(ret);
146}