-
Notifications
You must be signed in to change notification settings - Fork 18
/
tell.c
88 lines (78 loc) · 2.81 KB
/
tell.c
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
//*****************************************************************************
// Copyright (c) 2018 - Allen Cummings, RealmsMUD, All rights reserved. See
// the accompanying LICENSE file for details.
//*****************************************************************************
inherit "/lib/commands/baseCommand.c";
#include "/lib/include/settings.h"
#include <mtypes.h>
/////////////////////////////////////////////////////////////////////////////
public nomask void reset(int arg)
{
if (!arg)
{
addCommandTemplate("tell ##Target## ##Value##");
addCommandTemplate("reply ##Value##");
}
}
/////////////////////////////////////////////////////////////////////////////
private nomask object findTarget(string command)
{
object ret = 0;
string template = commandString(command);
if (command && stringp(command) && template && stringp(template))
{
string *targetId = regexplode(command, template);
if (sizeof(targetId) == 1)
{
string targetName = capitalize(regreplace(command, "tell ([A-Za-z]+) .*", "\\1", 1));
object *target = filter(users(),
(: return $1->Name() == $2; :), targetName);
if (sizeof(target))
{
ret = target[0];
}
}
}
return ret;
}
/////////////////////////////////////////////////////////////////////////////
public nomask int execute(string command, object initiator)
{
int ret = 0;
object target = findTarget(command);
string verb = "tell";
if (!target)
{
verb = "reply";
target = initiator->ReplyToUser();
}
if (objectp(target) && canExecuteCommand(command))
{
string message = sprintf("##InitiatorName## ##Infinitive::%s%s " +
"##TargetName##, `" + regreplace(command,
"(tell [^ ]+|reply) (.*)", "\\2", 1) + "'\n", verb,
(verb == "reply") ? "## to" : "##");
string targetMessage = formatText(parseTemplate(message, "target",
initiator, target), C_TELL, target);
ret = target->receiveMessage(initiator, targetMessage);
if (ret == Blocked)
{
tell_object(initiator, sprintf("Your message was not sent. You "
"have been blocked by %s.\n", capitalize(target->RealName()),
C_REPORT, initiator));
}
else if (ret == Busy)
{
tell_object(initiator, sprintf("Your message was not sent. %s "
"is busy.\n", capitalize(target->RealName()),
C_REPORT, initiator));
}
else
{
initiator->clearReplyTo();
tell_object(initiator, formatText(parseTemplate(message,
"initiator", initiator, target), C_TELL, initiator));
}
}
return ret;
}