blob: be31c6a9fbece5c838c300cb1f556fdc1ee3790d [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)
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);
Arathorn82058962018-01-05 23:42:05 +010022 SetProp(P_NODROP,1);
23 SetProp(P_NEVERDROP,1);
MG Mud User88f12472016-06-24 23:31:02 +020024 AddId(({"btool","balancetool","balance-tool"}));
25 SetProp(P_SHORT,"Ein Balance-Tool light");
26 SetProp(P_LONG,
27 BS("Dies ist das Balance-Tool light. Es versteht folgende Befehle:\n"
28 "- btop <n>: Zeigt den letzten genehmigten Antrag zu Top n.\n"
29 "- bsuch [-s] <str>: Sucht case-sensitiv nach str, -s bricht jeden "
30 "Eintrag nach 78 Zeichen ab.\n"
Bugfixed431842016-07-29 12:46:05 +020031 "- binhalt [-s] [uid]: Zeigt den gesamten Inhalt des Balancearchives, -s "
32 "bricht jeden Eintrag nach 78 Zeichen ab, uid filtert auf "
33 "_vollstaendige_ uids.\n\n"
MG Mud User88f12472016-06-24 23:31:02 +020034 "Es kann vorkommen, dass Eintraege der falschen UID zugeordnet sind, "
35 "oder dass die Genehmigung nicht sehr aussagekraeftig ist, in diesem "
36 "Fall bitte eine Mail an das Balanceteam schreiben."));
37 AddCmd("btop",
38 function int(string str)
39 {
40 int n;
41 if(!str || sscanf(str,"%d",n)!=1)
42 {
43 notify_fail(
44 BS("Syntax: btop <n>"));
45 return 0;
46 }
47 this_interactive()->ReceiveMsg(
48 BARCHIV->GetLightAnnounce(n),
49 MT_NOTIFICATION|MSG_BS_LEAVE_LFS);
50 return 1;
51 });
52 AddCmd("bsuch",
53 function int()
54 {
55 string str=this_interactive()->_unparsed_args();
56 if(!str || !sizeof(str))
57 {
58 notify_fail(
59 BS("Syntax: bsuch <str>"));
60 return 0;
61 }
62 int short;
63 string* arr=old_explode(str," ");
64
65 if(arr[0]=="-s")
66 {
67 short=1;
68 str=implode(arr[1..]," ");
69 }
70 mapping tmp=BARCHIV->SearchIndex(str);
71 if(!sizeof(tmp))
72 {
73 this_interactive()->ReceiveMsg(
74 "Keine Eintraege gefunden.",
75 MT_NOTIFICATION);
76 }
77 else
78 {
79 print_map(tmp,short);
80 }
81 return 1;
82 });
83 AddCmd("binhalt",
84 function int(string str)
85 {
86 int short;
Bugfixed431842016-07-29 12:46:05 +020087 string check;
88
89 mapping tmp=BARCHIV->GetIndexForWizards();
MG Mud User88f12472016-06-24 23:31:02 +020090 if(sizeof(str))
91 {
92 string* arr=old_explode(str," ");
93
94 if(arr[0]=="-s")
95 {
96 short=1;
Bugfixed431842016-07-29 12:46:05 +020097 if(sizeof(arr)>=2)
98 {
99 check=arr[1];
100 }
101 }
102 else
103 {
104 check=arr[0];
105 }
106
107 if(sizeof(check))
108 {
109 tmp=filter(tmp,
Bugfixe75df3c2016-07-29 13:11:21 +0200110 function int(int key, <int|string>* values)
Bugfixed431842016-07-29 12:46:05 +0200111 {
Bugfixe75df3c2016-07-29 13:11:21 +0200112 return values[2]==check;
Bugfixed431842016-07-29 12:46:05 +0200113 });
MG Mud User88f12472016-06-24 23:31:02 +0200114 }
115 }
116
Bugfixed431842016-07-29 12:46:05 +0200117 print_map(tmp,short);
MG Mud User88f12472016-06-24 23:31:02 +0200118 return 1;
119 });
120}
121
122private varargs void print_map(mapping tmp,int short)
123{
124 if (!mappingp(tmp))
125 {
126 this_interactive()->ReceiveMsg("Keine Daten vorhanden.\n");
127 return;
128 }
129 int* sort=sort_array(m_indices(tmp),#'>);
130 string ret="";
131 foreach(int i : sort)
132 {
133 string str=sprintf(" %4d: %s {%s} (%s)",i,tmp[i,0],tmp[i,2],
134 strftime("%d.%m.%y",tmp[i,1]));
135 if(short)
136 {
137 ret+=BS(str[0..77]);
138 }
139 else
140 {
141 ret+=BS(str);
142 }
143 }
144 this_interactive()->More(ret);
145}