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" |
| 28 | "- binhalt [-s]: Zeigt den gesamten Inhalt des Balancearchives, -s " |
| 29 | "bricht jeden Eintrag nach 78 Zeichen ab.\n\n" |
| 30 | "Es kann vorkommen, dass Eintraege der falschen UID zugeordnet sind, " |
| 31 | "oder dass die Genehmigung nicht sehr aussagekraeftig ist, in diesem " |
| 32 | "Fall bitte eine Mail an das Balanceteam schreiben.")); |
| 33 | AddCmd("btop", |
| 34 | function int(string str) |
| 35 | { |
| 36 | int n; |
| 37 | if(!str || sscanf(str,"%d",n)!=1) |
| 38 | { |
| 39 | notify_fail( |
| 40 | BS("Syntax: btop <n>")); |
| 41 | return 0; |
| 42 | } |
| 43 | this_interactive()->ReceiveMsg( |
| 44 | BARCHIV->GetLightAnnounce(n), |
| 45 | MT_NOTIFICATION|MSG_BS_LEAVE_LFS); |
| 46 | return 1; |
| 47 | }); |
| 48 | AddCmd("bsuch", |
| 49 | function int() |
| 50 | { |
| 51 | string str=this_interactive()->_unparsed_args(); |
| 52 | if(!str || !sizeof(str)) |
| 53 | { |
| 54 | notify_fail( |
| 55 | BS("Syntax: bsuch <str>")); |
| 56 | return 0; |
| 57 | } |
| 58 | int short; |
| 59 | string* arr=old_explode(str," "); |
| 60 | |
| 61 | if(arr[0]=="-s") |
| 62 | { |
| 63 | short=1; |
| 64 | str=implode(arr[1..]," "); |
| 65 | } |
| 66 | mapping tmp=BARCHIV->SearchIndex(str); |
| 67 | if(!sizeof(tmp)) |
| 68 | { |
| 69 | this_interactive()->ReceiveMsg( |
| 70 | "Keine Eintraege gefunden.", |
| 71 | MT_NOTIFICATION); |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | print_map(tmp,short); |
| 76 | } |
| 77 | return 1; |
| 78 | }); |
| 79 | AddCmd("binhalt", |
| 80 | function int(string str) |
| 81 | { |
| 82 | int short; |
| 83 | if(sizeof(str)) |
| 84 | { |
| 85 | string* arr=old_explode(str," "); |
| 86 | |
| 87 | if(arr[0]=="-s") |
| 88 | { |
| 89 | short=1; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | print_map(BARCHIV->GetIndexForWizards(),short); |
| 94 | return 1; |
| 95 | }); |
| 96 | } |
| 97 | |
| 98 | private varargs void print_map(mapping tmp,int short) |
| 99 | { |
| 100 | if (!mappingp(tmp)) |
| 101 | { |
| 102 | this_interactive()->ReceiveMsg("Keine Daten vorhanden.\n"); |
| 103 | return; |
| 104 | } |
| 105 | int* sort=sort_array(m_indices(tmp),#'>); |
| 106 | string ret=""; |
| 107 | foreach(int i : sort) |
| 108 | { |
| 109 | string str=sprintf(" %4d: %s {%s} (%s)",i,tmp[i,0],tmp[i,2], |
| 110 | strftime("%d.%m.%y",tmp[i,1])); |
| 111 | if(short) |
| 112 | { |
| 113 | ret+=BS(str[0..77]); |
| 114 | } |
| 115 | else |
| 116 | { |
| 117 | ret+=BS(str); |
| 118 | } |
| 119 | } |
| 120 | this_interactive()->More(ret); |
| 121 | } |