@@ -57,7 +57,7 @@ ws.on('error', (_) => _);
57
57
ws .on <[string , string , number ]>(
58
58
' message' ,
59
59
({ data }) =>
60
- console .log (` ${data [0 ]} said "${data [1 ]}" and sent ${data [2 ]} attachments ` ),
60
+ console .log (` ${data [0 ]} said "${data [1 ]}" and sent ${data [2 ]} attachment(s). ` ),
61
61
);
62
62
63
63
// Remember this!
@@ -79,20 +79,76 @@ discord.on('MESSAGE_CREATE', async (message) => {
79
79
});
80
80
```
81
81
82
- <!--
82
+ #### Get a guild's statistics.
83
83
84
- const client = new Tpy(Deno.env.get('PYLON_TOKEN')!);
85
- const guildStats = await client.getGuildStats('759174794968301569');
84
+ ``` ts
85
+ const client = new Tpy (' PYLON_TOKEN' );
86
+ const guildStats = await client .getGuildStats (' GUILD_ID' );
86
87
const mostRecent = guildStats .find ((e ) =>
87
88
e .date === Math .min (... guildStats .map ((e ) => e .date ))
89
+ )! ;
90
+ const { date, events, executionMsAvg } = mostRecent ;
91
+
92
+ const mostRecentDateFormatted = new Date (date * 1000 ).toDateString ();
93
+ console .log (
94
+ ` On ${mostRecentDateFormatted }, there was a total of ${events } events with an average execution time of ${executionMsAvg } (in ms). ` ,
95
+ );
96
+ ```
97
+
98
+ #### Get a deployment's listening events and cron tasks.
99
+
100
+ ``` ts
101
+ const client = new Tpy (' PYLON_TOKEN' );
102
+ const { config } = await client .getDeploymentfromGuild (' GUILD_ID' );
103
+ const { cronTasks } = config .tasks ;
104
+ const { events } = config ;
105
+ const cronTasksFormatted = cronTasks .map (({ cronString , name }) =>
106
+ ` ${name } (${cronString }) `
107
+ );
108
+
109
+ console .log (
110
+ ` Listening to ${events .length } discord event(s):
111
+ ${events .join (' , ' )}\n ` ,
112
+ ` Running ${cronTasks .length } cron job(s):\n ${cronTasksFormatted .join (' \n ' )} ` ,
113
+ );
114
+ ```
115
+
116
+ #### Get the keys in a KV namespace.
117
+
118
+ ``` ts
119
+ const client = new Tpy (' PYLON_TOKEN' );
120
+ const kvnamespace = ' tags' ;
121
+ const kv = client .KV (
122
+ kvnamespace ,
123
+ (await client .getDeploymentfromGuild (' GUILD_ID' )).id ,
88
124
);
89
- if (!mostRecent) throw '???';
90
- const mostRecentDateFormatted = new Date(mostRecent.date).getMilliseconds();
91
- console.log(mostRecentDateFormatted);
92
125
93
- -->
126
+ const keys = await kv .list ({ limit: 10 });
127
+ const amountOfKeys = await kv .count ();
128
+
129
+ console .log (
130
+ ` There are ${amountOfKeys } key(s) within the ${kvnamespace } KV namespace, these are the first 10 (or less).
131
+ ${keys .join (' , ' )} ` ,
132
+ );
133
+ ```
94
134
95
- <!-- TODO: add more examples; ws, kv, post deployment, other get stuff -->
135
+ #### Get and modify values within a KV namespace.
136
+
137
+ ``` ts
138
+ const client = new Tpy (' PYLON_TOKEN' );
139
+ const kvnamespace = ' tags' ;
140
+ const kv = client .KV (
141
+ kvnamespace ,
142
+ (await client .getDeploymentfromGuild (' GUILD_ID' )).id ,
143
+ );
144
+
145
+ const key = ' cool' ;
146
+ console .log (` Value of key "${key }": ` , await kv .get (key ));
147
+ await kv .put (key , ' rust' );
148
+ console .log (` Value of key "${key }": ` , await kv .get (key ));
149
+ await kv .delete (key );
150
+ console .log (` Value of key "${key }": ` , await kv .get (key ));
151
+ ```
96
152
97
153
## Contributing
98
154
0 commit comments