public async Task EditCustReact(kwum id, [Leftover] string message) { var channel = ctx.Channel as ITextChannel; if (string.IsNullOrWhiteSpace(message) || id < 0) { return; } if ((channel == null && !_creds.IsOwner(ctx.User)) || (channel != null && !((IGuildUser)ctx.User).GuildPermissions.Administrator)) { await ReplyErrorLocalizedAsync("insuff_perms").ConfigureAwait(false); return; } var cr = await _service.EditAsync(ctx.Guild?.Id, (int)id, message).ConfigureAwait(false); if (cr != null) { await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithTitle(GetText("edited_cust_react")) .WithDescription($"#{id}") .AddField(efb => efb.WithName(GetText("trigger")).WithValue(cr.Trigger)) .AddField(efb => efb.WithName(GetText("response")).WithValue(message.Length > 1024 ? GetText("redacted_too_long") : message)) ).ConfigureAwait(false); } else { await ReplyErrorLocalizedAsync("edit_fail").ConfigureAwait(false); } }
public void TestNotEqual() { var num1 = new kwum("hgbk5d"); var num2 = new kwum("hgbk4d"); Assert.AreNotEqual(num1, num2); }
private async Task InternalCrEdit(kwum id, CustomReactionsService.CrField option) { var cr = _service.GetCustomReaction(ctx.Guild?.Id, id); if (!AdminInGuildOrOwnerInDm()) { await ReplyErrorLocalizedAsync("insuff_perms").ConfigureAwait(false); return; } var(success, newVal) = await _service.ToggleCrOptionAsync(id, option).ConfigureAwait(false); if (!success) { await ReplyErrorLocalizedAsync("no_found_id").ConfigureAwait(false); return; } if (newVal) { await ReplyConfirmLocalizedAsync("option_enabled", Format.Code(option.ToString()), Format.Code(id.ToString())).ConfigureAwait(false); } else { await ReplyConfirmLocalizedAsync("option_disabled", Format.Code(option.ToString()), Format.Code(id.ToString())).ConfigureAwait(false); } }
public void TestConversionsToFromInt() { var num = new kwum(10); Assert.AreEqual(10, (int)num); Assert.AreEqual(num, (kwum)10); }
public void TestEqual() { var num1 = new kwum("hgbkhd"); var num2 = new kwum("hgbkhd"); Assert.AreEqual(num1, num2); }
public void TestLongEqualGetHashCode() { var num1 = new kwum("hgbkhdbk"); var num2 = new kwum("hgbkhdbk"); Assert.AreEqual(num1.GetHashCode(), num2.GetHashCode()); }
public void TestNotEqualGetHashCode() { var num1 = new kwum("234"); var num2 = new kwum("235"); Assert.AreNotEqual(num1.GetHashCode(), num2.GetHashCode()); }
public void TestMaxValue() { var num = new kwum(int.MaxValue - 1); Assert.AreEqual("3zzzzzy", num.ToString()); num = new kwum(int.MaxValue); Assert.AreEqual("3zzzzzz", num.ToString()); }
public void TestConverstionsToString() { var num = new kwum(10); Assert.AreEqual("c", num.ToString()); num = new kwum(123); Assert.AreEqual("5v", num.ToString()); // leading zeros have no meaning Assert.AreEqual(new kwum("22225v"), num); }
public async Task ShowCustReact(kwum id) { var found = _service.GetCustomReaction(ctx.Guild?.Id, (int)id); if (found == null) { await ReplyErrorLocalizedAsync("no_found_id").ConfigureAwait(false); return; } else { await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithDescription($"#{id}") .AddField(efb => efb.WithName(GetText("trigger")).WithValue(found.Trigger.TrimTo(1024))) .AddField(efb => efb.WithName(GetText("response")).WithValue((found.Response + "\n```css\n" + found.Response).TrimTo(1020) + "```")) ).ConfigureAwait(false); } }
public async Task DelCustReact(kwum id) { if (!AdminInGuildOrOwnerInDm()) { await ReplyErrorLocalizedAsync("insuff_perms").ConfigureAwait(false); return; } var cr = await _service.DeleteAsync(ctx.Guild?.Id, (int)id); if (cr != null) { await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithTitle(GetText("deleted")) .WithDescription($"#{id}") .AddField(efb => efb.WithName(GetText("trigger")).WithValue(cr.Trigger.TrimTo(1024))) .AddField(efb => efb.WithName(GetText("response")).WithValue(cr.Response.TrimTo(1024)))).ConfigureAwait(false); } else { await ReplyErrorLocalizedAsync("no_found_id").ConfigureAwait(false); } }
public Task CrAt(kwum id) => InternalCrEdit(id, CustomReactionsService.CrField.AllowTarget);
public Task CrAd(kwum id) => InternalCrEdit(id, CustomReactionsService.CrField.AutoDelete);
public Task CrDm(kwum id) => InternalCrEdit(id, CustomReactionsService.CrField.DmResponse);
public Task CrCa(kwum id) => InternalCrEdit(id, CustomReactionsService.CrField.ContainsAnywhere);
public async Task CrReact(kwum id, params string[] emojiStrs) { if (!AdminInGuildOrOwnerInDm()) { await ReplyErrorLocalizedAsync("insuff_perms").ConfigureAwait(false); return; } var cr = _service.GetCustomReaction(Context.Guild?.Id, id); if (cr is null) { await ReplyErrorLocalizedAsync("no_found").ConfigureAwait(false); return; } if (emojiStrs.Length == 0) { await _service.ResetCrReactions(ctx.Guild?.Id, id); await ReplyConfirmLocalizedAsync("crr_reset", Format.Bold(id.ToString())).ConfigureAwait(false); return; } List <string> succ = new List <string>(); foreach (var emojiStr in emojiStrs) { var emote = emojiStr.ToIEmote(); // i should try adding these emojis right away to the message, to make sure the bot can react with these emojis. If it fails, skip that emoji try { await Context.Message.AddReactionAsync(emote).ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false); succ.Add(emojiStr); if (succ.Count >= 3) { break; } } catch { } } if (succ.Count == 0) { await ReplyErrorLocalizedAsync("invalid_emojis").ConfigureAwait(false); return; } await _service.SetCrReactions(ctx.Guild?.Id, id, succ); await ReplyConfirmLocalizedAsync("crr_set", Format.Bold(id.ToString()), string.Join(", ", succ.Select(x => x.ToString()))).ConfigureAwait(false); }