1 module dscord.client;
2 
3 import std.stdio;
4 
5 public import std.experimental.logger;
6 
7 import std.algorithm.iteration;
8 
9 import dscord.state,
10        dscord.api.client,
11        dscord.gateway.client,
12        dscord.voice.client,
13        dscord.types.all,
14        dscord.util.emitter;
15 
16 class Client {
17   // Log
18   Logger  log;
19 
20   // User auth token
21   string  token;
22 
23   // Clients
24   APIClient      api;
25   GatewayClient  gw;
26 
27   // Voice connections
28   VoiceClient[Snowflake]  voiceConns;
29 
30   // State
31   State  state;
32 
33   // Emitters
34   Emitter  events;
35   Emitter  packets;
36 
37   this(string token, LogLevel lvl=LogLevel.all) {
38     this.log = new FileLogger(stdout, lvl);
39     this.token = token;
40 
41     this.api = new APIClient(this);
42     this.gw = new GatewayClient(this);
43     this.state = new State(this);
44   }
45 
46   /**
47     Returns the current user.
48   */
49   @property User me() {
50     return this.state.me;
51   }
52 
53   /**
54     Deletes an array of message IDs for a given channel, properly bulking them
55     if required.
56 
57     Params:
58       channelID = the channelID all the messages originate from
59       messages = the array of message IDs
60   */
61   void deleteMessages(Snowflake channelID, Snowflake[] messages) {
62     if (messages.length <= 2) {
63       messages.each!(x => this.api.deleteMessage(channelID, x));
64     } else {
65       this.api.bulkDeleteMessages(channelID, messages);
66     }
67   }
68 }