public async Task <string> GetMyChannelNameAsync(IGuild guild) { if (AnimeSubscription.ContainsKey(guild.Id)) { var chan = await guild.GetTextChannelAsync(AnimeSubscription[guild.Id]); if (chan == null) { return("Deleted channel"); } return(chan.Mention); } return("None"); }
public async Task AddAnimeSubscription(ITextChannel chan) { string guildIdStr = chan.GuildId.ToString(); string channelIdStr = chan.Id.ToString(); await R.Db(dbName).Table("Guilds").Update(R.HashMap("id", guildIdStr) .With("animeSubscription", channelIdStr) ).RunAsync(conn); if (AnimeSubscription.Any(x => x.Item1.Id == chan.Id)) { AnimeSubscription.Remove(AnimeSubscription.Where(x => x.Item1.Id == chan.Id).ElementAt(0)); } AnimeSubscription.Add((chan, null)); }
public async Task <bool> RemoveAnimeSubscription(IGuild guild) { string guildIdStr = guild.Id.ToString(); dynamic json = await R.Db(dbName).Table("Guilds").Get(guildIdStr).RunAsync(conn); string anime = (string)json.animeSubscription; if (anime == null || anime == "0") { return(false); } await R.Db(dbName).Table("Guilds").Update(R.HashMap("id", guildIdStr) .With("animeSubscription", "0") ).RunAsync(conn); var id = ulong.Parse(anime); AnimeSubscription.Remove(AnimeSubscription.Where(x => x.Item1.Id == id).ElementAt(0)); return(true); }
public async Task InitAsync(string dbName) { this.dbName = dbName; conn = await R.Connection().ConnectAsync(); if (!await R.DbList().Contains(dbName).RunAsync <bool>(conn)) { R.DbCreate(dbName).Run(conn); } if (!await R.Db(dbName).TableList().Contains("Guilds").RunAsync <bool>(conn)) { R.Db(dbName).TableCreate("Guilds").Run(conn); } if (!await R.Db(dbName).TableList().Contains("Anime").RunAsync <bool>(conn)) { R.Db(dbName).TableCreate("Anime").Run(conn); } foreach (dynamic elem in await R.Db(dbName).Table("Anime").RunAsync(conn)) { AnimeSubscription.Add(ulong.Parse((string)elem.id), ulong.Parse((string)elem.channel)); } }
public async Task AddAnimeSubscription(ulong guildId, ulong channelId) { string guildIdStr = guildId.ToString(); string channelIdStr = channelId.ToString(); if (await R.Db(dbName).Table("Anime").GetAll(guildIdStr).Count().Eq(0).RunAsync <bool>(conn)) { await R.Db(dbName).Table("Anime").Insert(R.HashMap("id", guildIdStr) .With("channel", channelIdStr) ).RunAsync(conn); AnimeSubscription.Add(guildId, channelId); } else { await R.Db(dbName).Table("Anime").Update(R.HashMap("id", guildIdStr) .With("channel", channelIdStr) ).RunAsync(conn); AnimeSubscription[guildId] = channelId; } }