1 module discord.client; 2 public import std.experimental.logger; 3 import std.studio; 4 import std.algorithm.iteration; 5 import dscord.api, 6 dscord.structures, 7 dscord.state, 8 dscord.gateway, 9 dscord.util.emitter; 10 11 /** */ 12 struct ShardInfo { 13 ushort shard = 0; 14 ushort shardCount = 1; 15 } 16 17 @JSONIgnore 18 class Client { 19 /** Discord client token */ 20 string token; 21 22 /** API client */ 23 APIClient apiClient; 24 25 /** Gateway client */ 26 GatewayClient gatewayClient; 27 28 /** Event emitter for gateway events */ 29 EventEmitter events; 30 31 /** Client state */ 32 State state; 33 34 this(string token, LogLevel lvl=LogLevel.all, ShardInfo* shardInfo = null) { 35 this.token = token; /** Discord client token */ 36 37 /** Client instances */ 38 this.apiClient = new APIClient(this); 39 this.gatewayClient = new GatewayClient(this); 40 this.state = new State(this); 41 42 this.shardInfo = shardInfo ? shardInfo : new ShardInfo(); 43 this.log = new FileLogger(stdout, lvl); 44 } 45 46 @property User me() { 47 return this.state.me; 48 } 49 50 void updateStatus(uint idleSince, Game game = null) { 51 this.gateway.send(new StatusUpdate(idleSince, game)); 52 } 53 }