public async Task GiveMuteAsync() { var user = Context.User as SocketGuildUser; if (user == null) { return; } using (var db = new Database.GuildConfigContext(Config)) { var config = await db.GetCachedGuildFullConfigAsync(Context.Guild.Id); if (config == null) { await ReplyAsync("", embed : "Serwer nie jest poprawnie skonfigurowany.".ToEmbedMessage(EMType.Bot).Build()); return; } var notifChannel = Context.Guild.GetTextChannel(config.NotificationChannel); var userRole = Context.Guild.GetRole(config.UserRole); var muteRole = Context.Guild.GetRole(config.MuteRole); if (muteRole == null) { await ReplyAsync("", embed : "Rola wyciszająca nie jest ustawiona.".ToEmbedMessage(EMType.Bot).Build()); return; } if (user.Roles.Contains(muteRole)) { await ReplyAsync("", embed : $"{user.Mention} już jest wyciszony.".ToEmbedMessage(EMType.Error).Build()); return; } var session = new AcceptSession(user, null, Context.Client.CurrentUser); await _session.KillSessionIfExistAsync(session); var msg = await ReplyAsync("", embed : $"{user.Mention} na pewno chcesz muta?".ToEmbedMessage(EMType.Error).Build()); await msg.AddReactionsAsync(session.StartReactions); session.Actions = new AcceptMute(Config) { NotifChannel = notifChannel, Moderation = _moderation, MuteRole = muteRole, UserRole = userRole, Message = msg, User = user, }; session.Message = msg; await _session.TryAddSession(session); } }
public async Task ReportUserAsync([Summary("id wiadomości")] ulong messageId, [Summary("powód")][Remainder] string reason) { using (var db = new Database.GuildConfigContext(Config)) { var config = await db.GetCachedGuildFullConfigAsync(Context.Guild.Id); if (config == null) { await ReplyAsync("", embed : "Serwer nie jest jeszcze skonfigurowany.".ToEmbedMessage(EMType.Bot).Build()); return; } var raportCh = Context.Guild.GetTextChannel(config.RaportChannel); if (raportCh == null) { await ReplyAsync("", embed : "Serwer nie ma skonfigurowanych raportów.".ToEmbedMessage(EMType.Bot).Build()); return; } await Context.Message.DeleteAsync(); var repMsg = await Context.Channel.GetMessageAsync(messageId); if (repMsg == null) { await ReplyAsync("", embed : "Nie odnaleziono wiadomości.".ToEmbedMessage(EMType.Error).Build()); return; } if (repMsg.Author.IsBot || repMsg.Author.IsWebhook) { await ReplyAsync("", embed : "Raportować bota? Bez sensu.".ToEmbedMessage(EMType.Bot).Build()); return; } if ((DateTime.Now - repMsg.CreatedAt.DateTime.ToLocalTime()).TotalHours > 3) { await ReplyAsync("", embed : "Można raportować tylko wiadomośći, które nie są starsze jak 3h.".ToEmbedMessage(EMType.Bot).Build()); return; } if (repMsg.Author.Id == Context.User.Id) { var user = Context.User as SocketGuildUser; if (user == null) { return; } var notifChannel = Context.Guild.GetTextChannel(config.NotificationChannel); var userRole = Context.Guild.GetRole(config.UserRole); var muteRole = Context.Guild.GetRole(config.MuteRole); if (muteRole == null) { await ReplyAsync("", embed : "Rola wyciszająca nie jest ustawiona.".ToEmbedMessage(EMType.Bot).Build()); return; } if (user.Roles.Contains(muteRole)) { await ReplyAsync("", embed : $"{user.Mention} już jest wyciszony.".ToEmbedMessage(EMType.Error).Build()); return; } var session = new AcceptSession(user, null, Context.Client.CurrentUser); await _session.KillSessionIfExistAsync(session); var msg = await ReplyAsync("", embed : $"{user.Mention} raportujesz samego siebie? Może pomoge! Na pewno chcesz muta?".ToEmbedMessage(EMType.Error).Build()); await msg.AddReactionsAsync(session.StartReactions); session.Actions = new AcceptMute(Config) { NotifChannel = notifChannel, Moderation = _moderation, MuteRole = muteRole, UserRole = userRole, Message = msg, User = user, }; session.Message = msg; await _session.TryAddSession(session); return; } await ReplyAsync("", embed : "Wysłano zgłoszenie.".ToEmbedMessage(EMType.Success).Build()); string userName = $"{Context.User.Username}({Context.User.Id})"; var sendMsg = await raportCh.SendMessageAsync($"{repMsg.GetJumpUrl()}", embed : "prep".ToEmbedMessage().Build()); try { await sendMsg.ModifyAsync(x => x.Embed = _helper.BuildRaportInfo(repMsg, userName, reason, sendMsg.Id)); var rConfig = await db.GetGuildConfigOrCreateAsync(Context.Guild.Id); rConfig.Raports.Add(new Database.Models.Configuration.Raport { User = repMsg.Author.Id, Message = sendMsg.Id }); await db.SaveChangesAsync(); } catch (Exception ex) { _logger.Log($"in raport: {ex}"); await sendMsg.DeleteAsync(); } } }