1 // Ported from the AutoOp example plugin in the XChat plugin documentation.
2 module example.autoop_capi;
3 
4 import hexchat.capi;
5 
6 enum PNAME = "AutoOp";
7 enum PDESC = "Auto Ops anyone that joins";
8 enum PVERSION = "0.1";
9 
10 __gshared hexchat_plugin *ph;   /* plugin handle */
11 int enable = 1;
12 
13 extern(C):
14 
15 version(Windows)
16 {
17    import core.sys.windows.dll : SimpleDllMain;
18    mixin SimpleDllMain;
19 }
20 
21 int join_cb(const(char)** word, void* userdata)
22 {
23    if (enable)
24       /* Op ANYONE who joins */
25       hexchat_commandf(ph, "OP %s", word[1]);
26    /* word[1] is the nickname, as in the Settings->Advanced->TextEvents window in xchat */
27 
28 	char* nul = null;
29 	*nul = 0;
30 
31    return HEXCHAT_EAT_NONE;  /* don't eat this event, xchat needs to see it! */
32 }
33 
34 int autooptoggle_cb(const(char)** word, const(char)** word_eol, void* userdata)
35 {
36    if (!enable)
37    {
38       enable = 1;
39       hexchat_print(ph, "AutoOping now enabled!\n");
40    } else
41    {
42       enable = 0;
43       hexchat_print(ph, "AutoOping now disabled!\n");
44    }
45 
46    char* nul = null;
47    *nul = 0;
48 
49    return HEXCHAT_EAT_ALL;   /* eat this command so xchat and other plugins can't process it */
50 }
51 
52 export void hexchat_plugin_get_info(const(char)** name, const(char)** desc, const(char)** version_, void** reserved)
53 {
54    *name = PNAME;
55    *desc = PDESC;
56    *version_ = PVERSION;
57 }
58 
59 export int hexchat_plugin_init(hexchat_plugin* plugin_handle,
60                       const(char)** plugin_name,
61                       const(char)** plugin_desc,
62                       const(char)** plugin_version,
63                       char* arg)
64 {
65    /* we need to save this for use with any xchat_* functions */
66    ph = plugin_handle;
67 
68    /* tell xchat our info */
69    *plugin_name = PNAME;
70    *plugin_desc = PDESC;
71    *plugin_version = PVERSION;
72 
73    hexchat_hook_command(ph, "AutoOpToggle", HEXCHAT_PRI_NORM, &autooptoggle_cb, "Usage: AUTOOPTOGGLE, Turns OFF/ON Auto Oping", null);
74    hexchat_hook_print(ph, "Join", HEXCHAT_PRI_NORM, &join_cb, null);
75 
76    hexchat_print(ph, "AutoOpPlugin loaded successfully!\n");
77 
78    return 1;       /* return 1 for success */
79 }
80