-
Notifications
You must be signed in to change notification settings - Fork 0
/
discordbot.sc
100 lines (74 loc) · 3.59 KB
/
discordbot.sc
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
__config() -> {'stay_loaded' -> true,'scope'->'global','bot'->'GCP Minecraft Bot'};
get_dc_channel() -> (return(dc_channel_from_id('798960815617081345')));
get_world_name_by_folder() -> (return(split('/',system_info('world_path')):(-2))); // or alternatively (return(system_info('world_name')))
__on_discord_message(message) -> (
if(message~'user'~'is_self',
if(message~'readable_content' != '' && slice(message~'readable_content',0,1)=='<' && split('>',split('@',message~'readable_content'):1):0 != get_world_name_by_folder(),
run('tellraw @a {"text":"' + replace(message~'readable_content','\n','\\\\n') + '", "color":"white"}');
);
return();
);
if(message~'channel'!=get_dc_channel()~'name',return());
text = message~'content';
if(slice(text,0,1)=='!',
(
cmd = split(' ',slice(text,1)):0;
cmdParams = reduce(split(' ',slice(text,1)),put(_a,split('=',_):0,split('=',_):1);_a,{});
if(cmd == 'list' && length(cmdParams)==1,
e = dc_build_embed();
dc_build_embed(e,'title','Players Currently Online('+get_world_name_by_folder()+'):');
for(player('all'),
age_in_seconds = floor(query(_,'age')/20);
age_h=floor(age_in_seconds/3600);
age_m=floor((age_in_seconds%3600)/60);
age_s=(age_in_seconds%60);
age_to_print='';
age_to_print= age_to_print+if(age_h<10,'0'+age_h,age_h);
age_to_print= age_to_print+if(age_m<10,':0'+age_m,':'+age_m);
age_to_print= age_to_print+if(age_s<10,':0'+age_s,':'+age_s);
dc_build_embed(e,'add_field',_,'Has been online for: '+age_to_print);
);
dc_send_message(get_dc_channel(),e);
// dc_send_message(message~'channel','Currently online: ' + join(', ',player('all')));
return();
);
if(cmd == 'list' && has(cmdParams,'world') && lower(get(cmdParams,'world'))==lower(get_world_name_by_folder()) ,
e_header = dc_build_embed();
dc_build_embed(e_header,'title','Players Currently Online('+get_world_name_by_folder()+'):');
dc_send_message(get_dc_channel(),e_header);
for(player('all'),
(
e = dc_build_embed();
dc_build_embed(e,'title',_);
dc_build_embed(e,'thumbnail','https://crafthead.net/helm/'+_);
dc_send_message(get_dc_channel(),e);)
);
// dc_send_message(message~'channel','Currently online: ' + join(', ',player('all')));
return();
);
//if(cmd == 'help', //!help command
// dc_send_message(message~'channel','I\'m sorry but i cant help you');
// return();
//);
),
run('tellraw @a {"text":"<' + dc_get_display_name(message~'user',message~'server') + '@Discord> '
+ replace(message~'readable_content','\n','\\\\n') + '", "color":"blue"}');
);
);
__on_chat_message(message,player,command) -> (
if(!command,
dc_send_message(get_dc_channel(), '<'+player+'@' + get_world_name_by_folder() + '> '+message);
);
);
__on_player_connects(player) -> (
dc_send_message(get_dc_channel(), player+' logged onto the ' + get_world_name_by_folder() + ' server!')
);
__on_player_disconnects(player,reason) -> (
dc_send_message(get_dc_channel(), player+' logged out from the ' + get_world_name_by_folder() + ' server!')
);
__on_server_starts() -> {
dc_send_message(get_dc_channel(), get_world_name_by_folder() + ' Server Started!')
};
__on_server_shuts_down() -> {
dc_send_message(get_dc_channel(), get_world_name_by_folder() + ' Server Shutting Down')
}