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