MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | #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 | |
| 6 | inherit "/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 | |
| 15 | private varargs void print_map(mapping tmp,int short); |
| 16 | |
| 17 | protected void create() |
| 18 | { |
| 19 | ::create(); |
| 20 | SetProp(P_NAME,"Balance-Tool"); |
Bugfix | efe25e9 | 2016-07-29 13:14:01 +0200 | [diff] [blame] | 21 | SetProp(P_AUTOLOADOBJ,1); |
Arathorn | 8205896 | 2018-01-05 23:42:05 +0100 | [diff] [blame^] | 22 | SetProp(P_NODROP,1); |
| 23 | SetProp(P_NEVERDROP,1); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 24 | 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" |
Bugfix | ed43184 | 2016-07-29 12:46:05 +0200 | [diff] [blame] | 31 | "- 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 34 | "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; |
Bugfix | ed43184 | 2016-07-29 12:46:05 +0200 | [diff] [blame] | 87 | string check; |
| 88 | |
| 89 | mapping tmp=BARCHIV->GetIndexForWizards(); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 90 | if(sizeof(str)) |
| 91 | { |
| 92 | string* arr=old_explode(str," "); |
| 93 | |
| 94 | if(arr[0]=="-s") |
| 95 | { |
| 96 | short=1; |
Bugfix | ed43184 | 2016-07-29 12:46:05 +0200 | [diff] [blame] | 97 | 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, |
Bugfix | e75df3c | 2016-07-29 13:11:21 +0200 | [diff] [blame] | 110 | function int(int key, <int|string>* values) |
Bugfix | ed43184 | 2016-07-29 12:46:05 +0200 | [diff] [blame] | 111 | { |
Bugfix | e75df3c | 2016-07-29 13:11:21 +0200 | [diff] [blame] | 112 | return values[2]==check; |
Bugfix | ed43184 | 2016-07-29 12:46:05 +0200 | [diff] [blame] | 113 | }); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
Bugfix | ed43184 | 2016-07-29 12:46:05 +0200 | [diff] [blame] | 117 | print_map(tmp,short); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 118 | return 1; |
| 119 | }); |
| 120 | } |
| 121 | |
| 122 | private 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 | } |