-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.extension.html
189 lines (134 loc) · 14 KB
/
file.extension.html
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="/favicon.png" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
File: Extension
— discorb v0.20.0 documentation
</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/common.css" type="text/css" />
<script type="text/javascript">
pathId = "extension";
relpath = '';
</script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="file_list.html?1"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="a_index.html">Index</a> »
<span class="title">File: Extension</span>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="class_list.html">
<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>
</div>
<div class="clear"></div>
</div>
<div id="content"><div id='filecontents'>
<h1 id="label-Extension">Extension</h1>
<p>Extension allows you to seperate events.</p>
<h2 id="label-Make+a+new+extension">Make a new extension</h2>
<p>Make a new class that includes Extension.</p>
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>MyExtension</span>
<span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="Discorb.html" title="Discorb (module)">Discorb</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Discorb/Extension.html" title="Discorb::Extension (module)">Extension</a></span></span>
<span class='comment'># ...
</span><span class='kw'>end</span>
</code></pre>
<h2 id="label-Register+Event">Register Event</h2>
<p>Use Discorb::Extension.event to register event, or Discorb::Extension.once_event to register event only once.</p>
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>MyExtension</span>
<span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="Discorb.html" title="Discorb (module)">Discorb</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Discorb/Extension.html" title="Discorb::Extension (module)">Extension</a></span></span>
<span class='id identifier rubyid_event'>event</span> <span class='symbol'>:message</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='op'>|</span>
<span class='comment'># ...
</span> <span class='kw'>end</span>
<span class='id identifier rubyid_once_event'>once_event</span> <span class='symbol'>:standby</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='op'>|</span>
<span class='comment'># ...
</span> <span class='kw'>end</span>
<span class='kw'>end</span>
</code></pre>
<p>Note block will be binded to the extension instance.</p>
<h2 id="label-Register+Command">Register Command</h2>
<p>Use <code>Discorb::Extension.command</code> to register command, see <span class='object_link'><a href="Discorb/ApplicationCommand/Handler.html" title="Discorb::ApplicationCommand::Handler (module)">Discorb::ApplicationCommand::Handler</a></span> for more information.</p>
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>MyExtension</span>
<span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="Discorb.html" title="Discorb (module)">Discorb</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Discorb/Extension.html" title="Discorb::Extension (module)">Extension</a></span></span>
<span class='id identifier rubyid_slash'>slash</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>command</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Command</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_interaction'>interaction</span><span class='op'>|</span>
<span class='comment'># ...
</span> <span class='kw'>end</span>
<span class='id identifier rubyid_slash_group'>slash_group</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>group</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Group</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_group'>group</span><span class='op'>|</span>
<span class='id identifier rubyid_group'>group</span><span class='period'>.</span><span class='id identifier rubyid_slash'>slash</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>subcommand</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Subcommand</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_interaction'>interaction</span><span class='op'>|</span>
<span class='comment'># ...
</span> <span class='kw'>end</span>
<span class='id identifier rubyid_group'>group</span><span class='period'>.</span><span class='id identifier rubyid_group'>group</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>subgroup</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Subcommand group</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_group'>group</span><span class='op'>|</span>
<span class='id identifier rubyid_group'>group</span><span class='period'>.</span><span class='id identifier rubyid_slash'>slash</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>group_subcommand</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Command in Subcommand group</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_interaction'>interaction</span><span class='op'>|</span>
<span class='comment'># ...
</span> <span class='kw'>end</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
</code></pre>
<h2 id="label-Load+extension">Load extension</h2>
<p>Use <span class='object_link'><a href="Discorb/Client.html#load_extension-instance_method" title="Discorb::Client#load_extension (method)">Discorb::Client#load_extension</a></span> to load extension.</p>
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>MyExtension</span>
<span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="Discorb.html" title="Discorb (module)">Discorb</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Discorb/Extension.html" title="Discorb::Extension (module)">Extension</a></span></span>
<span class='id identifier rubyid_event'>event</span> <span class='symbol'>:message</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='op'>|</span>
<span class='comment'># ...
</span> <span class='kw'>end</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_load_extension'>load_extension</span><span class='lparen'>(</span><span class='const'>MyExtension</span><span class='rparen'>)</span>
</code></pre>
<h2 id="label-Access+Client+from+extension">Access Client from extension</h2>
<p>You can access <span class='object_link'><a href="Discorb/Client.html" title="Discorb::Client (class)">Discorb::Client</a></span> from extension with <code>@client</code>.</p>
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>MyExtension</span>
<span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="Discorb.html" title="Discorb (module)">Discorb</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Discorb/Extension.html" title="Discorb::Extension (module)">Extension</a></span></span>
<span class='id identifier rubyid_event'>event</span> <span class='symbol'>:standby</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='op'>|</span>
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Logged in as </span><span class='embexpr_beg'>#{</span><span class='ivar'>@client</span><span class='period'>.</span><span class='id identifier rubyid_user'>user</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
<span class='kw'>end</span>
<span class='kw'>end</span>
</code></pre>
<h2 id="label-Receiving+Arguments+on+load">Receiving Arguments on load</h2>
<p>You can receive arguments by adding some arguments to <code>#initialize</code>.</p>
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>MyExtension</span>
<span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="Discorb.html" title="Discorb (module)">Discorb</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Discorb/Extension.html" title="Discorb::Extension (module)">Extension</a></span></span>
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_client'>client</span><span class='comma'>,</span> <span class='id identifier rubyid_arg1'>arg1</span><span class='comma'>,</span> <span class='id identifier rubyid_arg2'>arg2</span><span class='rparen'>)</span>
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_client'>client</span><span class='rparen'>)</span>
<span class='comment'># @client = client will also work, but it's not recommended.
</span> <span class='ivar'>@arg1</span> <span class='op'>=</span> <span class='id identifier rubyid_arg1'>arg1</span>
<span class='ivar'>@arg2</span> <span class='op'>=</span> <span class='id identifier rubyid_arg2'>arg2</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_load_extension'>load_extension</span><span class='lparen'>(</span><span class='const'>MyExtension</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>arg1</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>arg2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
</code></pre>
<h2 id="label-Do+something+on+load">Do something on load</h2>
<p>You can do something on load by overriding <code>.loaded</code>. Client and arguments will be passed to it.</p>
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>MyExtension</span>
<span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="Discorb.html" title="Discorb (module)">Discorb</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Discorb/Extension.html" title="Discorb::Extension (module)">Extension</a></span></span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_loaded'>loaded</span><span class='lparen'>(</span><span class='id identifier rubyid_client'>client</span><span class='rparen'>)</span>
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>This extension is loaded to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_client'>client</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
<span class='kw'>end</span>
<span class='kw'>end</span>
</code></pre>
</div></div>
<div id="footer">
Generated on Sat Sep 3 22:19:57 2022 by
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.28 (ruby-3.0.2).
</div>
</div>
</body>
</html>