public static async Task SendChannel(IDiscordMessageChannel channel, IDiscordEmbed message) { if (channel.Guild.CurrentUser.HasPermissions(channel, DiscordGuildPermission.SendMessages)) { if (CanSendNotification(channel.Guild.Id, DatabaseEntityType.GUILD, DatabaseSettingId.CHANNELMESSAGE)) { await message.SendToChannel(channel); } } }
public static async Task SendChannel(IDiscordMessageChannel channel, string message) { if ((await channel.Guild.GetCurrentUserAsync()).HasPermissions(channel, DiscordGuildPermission.SendMessages)) { if (CanSendNotification(channel.Guild.Id, DatabaseSettingId.CHANNELMESSAGE)) { await channel.QueueMessageAsync(message); } } }
public void Start(IDiscordMessageChannel channel, TimeSpan span) { Task.Run(async() => { await Task.Delay((int)span.TotalMilliseconds); await CreateReminderEmbed(Text) .QueueToChannel(channel); parent.RemoveReminder(ReminderId); }, cancellationToken.Token); }
public async Task AddCurrencyAsync(int amount, IDiscordMessageChannel channel = null, User fromUser = null) { if (Banned) { return; } Currency += amount; if (channel != null) { await AchievementManager.Instance.CallTransactionMadeEventAsync(channel, this, fromUser, Currency); } }
public async Task RunTask(IDiscordMessageChannel channel) { await Task.Delay((int)Length.TotalMilliseconds); cancellationToken.Token.ThrowIfCancellationRequested(); CreateReminderEmbed(Text) .QueueToChannel(channel); if (RepeatReminder) { parent.CreateNewReminder(channel, Text, Length, RepeatReminder); } parent.RemoveReminder(ReminderId); }
public int CreateNewReminder(IDiscordMessageChannel channel, string text, TimeSpan at) { int?id = GetRandomKey(); if (id == null) { return(-1); } ReminderInstance reminder = new ReminderInstance(id.GetValueOrDefault(), this, text); reminder.Start(channel, at); instances.Add(id ?? 0, reminder); return(id.GetValueOrDefault()); }
public async Task <string> Print(int currentValue, IDiscordMessageChannel c) { string output = ""; IDiscordUser u = await c.Guild.GetUserAsync(Bot.Instance.CurrentUser.Id); if (!u.HasPermissions(c, DiscordGuildPermission.UseExternalEmojis)) { return(""); } int iteration = MaxValue / Width; int currentIteration = iteration; for (int i = 0; i < Width; i++) { output += (currentValue >= currentIteration) ? ValueOn.GetAppropriateSection(0, Width - 1, i) : ValueOff.GetAppropriateSection(0, Width - 1, i); currentIteration += iteration; } return(output); }
/// <summary> /// Unlocks the achievement and if not yet added to the database, It'll add it to the database. /// </summary> /// <param name="context">sql context</param> /// <param name="id">user id</param> /// <param name="r">rank set to (optional)</param> /// <returns></returns> internal async Task UnlockAsync(MikiContext context, IDiscordMessageChannel channel, IDiscordUser user, int r = 0) { long userid = user.Id.ToDbLong(); Achievement a = await context.Achievements.FindAsync(userid, ParentName); if (a != null || r != 0) { if (a.Rank == r - 1) { a.Rank += 1; await Notification.SendAchievement(this, channel, user); } } else { context.Achievements.Add(new Achievement() { Id = userid, Name = ParentName, Rank = 0 }); await Notification.SendAchievement(this, channel, user); } await context.SaveChangesAsync(); }
public async Task CallTransactionMadeEventAsync(IDiscordMessageChannel m, User receiver, User giver, int amount) { try { TransactionPacket p = new TransactionPacket(); p.discordChannel = m; p.discordUser = new RuntimeUser(Bot.instance.Client.GetUser(receiver.Id.FromDbLong())); if (giver != null) { p.giver = giver; } p.receiver = receiver; p.amount = amount; await OnTransaction?.Invoke(p); } catch (Exception e) { Log.WarningAt("achievement check failed", e.ToString()); } }
public async Task QueueToChannel(IDiscordMessageChannel channel) { Task.Run(async() => await SendToChannel(channel)); }
public async Task CallAchievementUnlockEventAsync(BaseAchievement achievement, IDiscordUser user, IDiscordMessageChannel channel) { if (achievement as AchievementAchievement != null) { return; } long id = user.Id.ToDbLong(); using (var context = new MikiContext()) { int achievementCount = await context.Achievements .AsNoTracking() .Where(q => q.Id == id) .CountAsync(); AchievementPacket p = new AchievementPacket() { discordUser = user, discordChannel = channel, achievement = achievement, count = achievementCount }; await OnAchievementUnlocked?.Invoke(p); } }
public async Task CallAchievementUnlockEventAsync(BaseAchievement achievement, IDiscordUser user, IDiscordMessageChannel channel) { if (achievement as AchievementAchievement != null) { return; } using (var context = new MikiContext()) { long id = user.Id.ToDbLong(); List <Achievement> achs = context.Achievements.Where(q => q.Id == id).ToList(); int achievementCount = achs.Sum(x => x.Rank + 1); AchievementPacket p = new AchievementPacket() { discordUser = user, discordChannel = channel, achievement = achievement, count = achievementCount }; await OnAchievementUnlocked?.Invoke(p); } }
public void Start(IDiscordMessageChannel channel) { Task.Run(() => RunTask(channel), cancellationToken.Token); }
public async Task <IDiscordMessage> SendToChannel(IDiscordMessageChannel channel) { return(await SendToChannel(channel.Id)); }
public Task <IDiscordMessage> SendToChannel(IDiscordMessageChannel channel) { throw new NotImplementedException(); }
public static async Task SendAchievement(AchievementDataContainer d, int rank, IDiscordMessageChannel channel, IDiscordUser user) { await SendAchievement(d.Achievements[rank], channel, user); }
public static Locale GetLocale(this IDiscordMessageChannel c) => new Locale(c.Id);
public static Locale GetLocale(this IDiscordMessageChannel c) => Locale.GetEntity(c.Id);
public static void SendAchievement(AchievementDataContainer d, int rank, IDiscordMessageChannel channel, IDiscordUser user) => SendAchievement(d.Achievements[rank], channel, user);