public async Task SetReaderAsync() { IGuildUser user = await this.Context.Guild.GetUserAsync(this.Context.User.Id); if (user == null) { // If the reader doesn't exist anymore, don't start a game. return; } // This needs to happen before we try creating a game string readerRolePrefix; using (DatabaseAction action = this.DatabaseActionFactory.Create()) { readerRolePrefix = await action.GetReaderRolePrefixAsync(this.Context.Guild.Id); } if (!user.CanRead(this.Context.Guild, readerRolePrefix)) { await this.Context.Channel.SendMessageAsync( @$ "{user.Mention} can't read because they don't have a role starting with the prefix " "{readerRolePrefix}" "."); return; } if (!(this.Manager.TryGet(this.Context.Channel.Id, out GameState state) || this.Manager.TryCreate(this.Context.Channel.Id, out state))) { // Couldn't add a new reader. return; }
public async Task SetNewReaderAsync(IGuildUser newReader) { if (newReader != null && this.Manager.TryGet(this.Context.Channel.Id, out GameState game)) { string readerRolePrefix; using (DatabaseAction action = this.DatabaseActionFactory.Create()) { readerRolePrefix = await action.GetReaderRolePrefixAsync(this.Context.Guild.Id); } if (!newReader.CanRead(this.Context.Guild, readerRolePrefix)) { await this.Context.Channel.SendMessageAsync( @$ "Cannot set {newReader.Mention} as the reader because they do not have a role with the reader prefix " "{readerRolePrefix}" ""); return; } game.ReaderId = newReader.Id; await this.Context.Channel.SendMessageAsync($"{newReader.Mention} is now the reader."); return; } if (this.Context.Channel is IGuildChannel guildChannel) { Logger.Information( "New reader called in guild '{0}' in channel '{1}' with ID that could not be found: {2}", guildChannel.Guild.Name, guildChannel.Name, newReader?.Id); } await this.Context.Channel.SendMessageAsync($"User could not be found. Could not set the new reader."); }