public async Task <RuntimeResult> SetProperty(string property, params string[] values) { try { var guildProperties = _guildPropertyStorage.EnsureGuildProperties(Context.Guild.Id); // parse possible user/role/channel values that are passed as id string var idRegex = new Regex(@"<[\#\!\@\&]+(\d+)>"); var parsedValues = new List <string>(); foreach (string value in values) { Match match = idRegex.Match(value); ulong id; if (match.Success && ulong.TryParse(match.Groups[1].Value, out id)) { var user = await Context.Guild.GetUserAsync(id); if (user != null) { parsedValues.Add(user.Username + "#" + user.Discriminator); continue; } var role = Context.Guild.GetRole(id); if (role != null) { parsedValues.Add(role.Name); continue; } var channel = await Context.Guild.GetChannelAsync(id); if (channel != null) { parsedValues.Add(channel.Name); continue; } } else { parsedValues.Add(value); } } // set parsed values guildProperties.SetProperty(property, string.Join(";", parsedValues)); _guildPropertyStorage.UpdateGuildProperties(guildProperties); await ReplyAsync("Ok"); return(CommandResult.FromSuccess()); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(CommandResult.FromError(ex.Message)); } }
public async Task PingDefaultChannel(ulong guildId, string message) { var guildProperties = _guildPropertyStorage.EnsureGuildProperties(guildId); var channelName = guildProperties.PingChannel; if (string.IsNullOrEmpty(channelName)) { throw new Exception("Default ping channel is not set"); } await PingChannel(guildId, channelName, message); }
public async Task <Dictionary <IUser, string> > GetTrackerUrlsDefault( ulong guildId, ulong authorId, string message) { var guildProperties = _guildPropertyStorage.EnsureGuildProperties(guildId); var channelName = guildProperties.PingChannel; if (string.IsNullOrEmpty(channelName)) { throw new Exception("Default ping channel is not set"); } return(await GetTrackerUrls(guildId, authorId, channelName, message)); }
private async Task PingEventAsync(ulong guildId, DateTime pingDate, ScheduledEvent se) { string message = string.Format( "**{0}\nFrom {1}:**\n{2}", se.ETA, se.User, se.Message); var properties = _guildPropertyStorage.EnsureGuildProperties(guildId); string channel; if (se.TargetDate > pingDate) { _logger.LogInformation("Pinging reminder for event {0}/[{1}]", guildId, se.Id); channel = properties.RemindChannel; if (string.IsNullOrEmpty(channel)) { _logger.LogInformation("Remind channel is not set, falling back on default"); channel = properties.PingChannel; if (string.IsNullOrEmpty(channel)) { throw new Exception("Neither remind, not default ping channel is set"); } } } else { _logger.LogInformation("Pinging main event {0}/[{1}]", guildId, se.Id); channel = properties.PingChannel; if (string.IsNullOrEmpty(channel)) { throw new Exception("Default ping channel is not set"); } } await _messagingService.PingChannel(guildId, channel, message); }