This repository has been archived by the owner on Feb 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
adminnotes.py
134 lines (111 loc) · 3.78 KB
/
adminnotes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from helpers import *
from traceback import format_exc as print_traceback
import time
an_permission = "utils.an";
notes = open_json_file("adminnotes", [])
continued_messages = {}
def save_notes():
save_json_file("adminnotes", notes)
def r_ago(unit, i):
# Return ago + plural
if i != 1:
unit += "s"
return "%s %s ago" % (i, unit)
def calc_diff(time_ago):
current = time.time()
s = current-time_ago
s = int(s)
ago = "Some time ago"
if s < 10:
ago = "Just now"
elif s >= 10 and s < 60:
ago = r_ago("second", s)
elif s >= 60 and s < 3600:
ago = r_ago("minute", s/60)
elif s >= 3600 and s < 43200:
ago = r_ago("hour", s/60/60)
elif s >= 43200:
ago = r_ago("day", s/60/60/12)
return ago
def show_all_notes(sender):
if len(notes) == 0:
msg(sender, "&aNo open notes at the moment!")
return
for i in range(0, len(notes)):
arr = notes[i]
name = arr[0]
message = arr[1]
note_time = arr[2]
ago = calc_diff(note_time)
msg(sender, "&6#%s - &e%s&6, %s:" % (str(i+1), name, ago))
msg(sender, "&7%s" % colorify(message))
def show_an_help(sender):
msg(sender, "&6AdminNotes Help:")
msg(sender, "&e- /an")
msg(sender, "&7&oLists all notes")
msg(sender, "&e- /an del <ID>")
msg(sender, "&7&oRemove a note")
msg(sender, "&e- /an help")
msg(sender, "&7&oShows this menu")
msg(sender, "&e- /an Some text...")
msg(sender, "&7&oWrite a new note")
msg(sender, "&e- /an This text is very++")
msg(sender, "&7&oContinue writing your note when using &e/an long guys!&7&o again")
@hook.command("an", aliases=["adminnotes", "adminnote"])
def adminnotes_command(sender, command, label, args):
if not sender.hasPermission(an_permission):
noperm(sender)
return
try:
arglen = len(args)
# arg length not valid
if arglen == 0:
show_all_notes(sender)
return
# Shows note help
subcmd = args[0].lower()
if subcmd == "help":
show_an_help(sender)
return
# Delete note
if subcmd == "del":
if arglen != 2:
show_an_help(sender)
return
if not args[1].isdigit():
msg(sender, "&cThe ID has to be numeric (check /an if you're unsure)")
return
note_id = int(args[1])-1
if note_id >= len(notes):
msg(sender, "&cThere is no note with that ID!")
return
# Deletes note by index
del notes[note_id]
save_notes()
msg(sender, "&aSuccessfully deleted note #%s!" % str(note_id+1))
return
message = " ".join(args)
name = sender.getName()
if name in continued_messages:
message = continued_messages[name] + " " + message
del continued_messages[name]
if message[-2:] == "++":
message = message[:-2]
continued_messages[name] = message
msg(sender, "&6You can continue writing by using &e/an <text ...>")
else:
notes.append([name, message, time.time()])
save_notes()
msg(sender, "&eNew note:&6 " + message)
broadcast(an_permission, "&a%s just added a new note! &2Type /an" % name)
except:
error(print_traceback())
@hook.event("player.PlayerJoinEvent", "monitor")
def on_an_join(event):
player = event.getPlayer()
if not player.hasPermission(an_permission):
return
if len(notes) > 0:
msg(player, "&cThere are currently %s open notes!" % len(notes))
elif len(notes) == 0:
msg(player, "&aThere are currently no open notes!")