mirror of
https://github.com/yawaflua/PL_JusticeBot.git
synced 2025-12-08 19:39:27 +02:00
add timer-cnhager nickname
This commit is contained in:
31
Justice.cs
31
Justice.cs
@@ -1,6 +1,7 @@
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using DiscordApp;
|
||||
using System.Timers;
|
||||
|
||||
namespace DiscordApp
|
||||
{
|
||||
@@ -28,13 +29,41 @@ namespace DiscordApp
|
||||
client.Log += LogAsync;
|
||||
client.UserJoined += Justice.Events.Events.onJoinGuild;
|
||||
client.MessageReceived += Justice.Events.Events.onMessageCreate;
|
||||
client.Ready += onReady;
|
||||
await client.LoginAsync(TokenType.Bot, "MTE2NjA3OTk3NjQ0NjEwMzYwMg.GAKOIo.4af972Wh11G0EF4O5tNYb7l-vt5OwMc4HPRnjE");
|
||||
await client.StartAsync();
|
||||
await interactionHandler.InitializeAsync();
|
||||
|
||||
await Task.Delay(Timeout.Infinite);
|
||||
}
|
||||
|
||||
public async Task onReady()
|
||||
{
|
||||
ChangeNicknames();
|
||||
var myTimer = new System.Timers.Timer(6 * 60 * 60 * 1000); //calculate six hours in milliseconds
|
||||
myTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
|
||||
myTimer.Start();
|
||||
}
|
||||
private async void OnTimedEvent(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
Console.WriteLine("Started timer");
|
||||
await ChangeNicknames();
|
||||
}
|
||||
private async Task ChangeNicknames()
|
||||
{
|
||||
IGuild guild = client.GetGuild(1107742957458685985);
|
||||
IRole role = guild.GetRole(1136564585420304444);
|
||||
var members = await guild.GetUsersAsync();
|
||||
var membersArray = members.ToArray();
|
||||
foreach (IGuildUser user in membersArray)
|
||||
{
|
||||
var spUser = await Startup.sp.GetUser(user.Id.ToString());
|
||||
if (spUser.IsPlayer())
|
||||
{
|
||||
await user.ModifyAsync(func => { func.Nickname = spUser.Name; });
|
||||
await user.AddRoleAsync(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
private async Task LogAsync(LogMessage message)
|
||||
=> Console.WriteLine(message.ToString());
|
||||
}
|
||||
|
||||
@@ -10,15 +10,15 @@ namespace DiscordApp.Justice.Interactions
|
||||
{
|
||||
[ComponentInteraction("NewIndividualEntrepreneur")]
|
||||
public async Task AplyWork()
|
||||
=> await Context.Interaction.RespondWithModalAsync<INewIndividualEntrepreneur>("newIndividualEterpreneur");
|
||||
=> await Context.Interaction.RespondWithModalAsync<INewIndividualEntrepreneur>("newIndividualEterpreneurModal");
|
||||
[ComponentInteraction("NewBizness")]
|
||||
public async Task reCreatePassport()
|
||||
=> await Context.Interaction.RespondWithModalAsync<INewBizness>("NewBizness");
|
||||
=> await Context.Interaction.RespondWithModalAsync<INewBizness>("NewBiznessModal");
|
||||
|
||||
[ModalInteraction("newIndividualEterpreneur")]
|
||||
[ModalInteraction("newIndividualEterpreneurModal")]
|
||||
public async Task newIndividualEterpreneur(INewIndividualEntrepreneur modal)
|
||||
{
|
||||
await DeferAsync(true);
|
||||
|
||||
Passport? applicant = await Startup.appDbContext.Passport.FindAsync(int.Parse(modal.passportId));
|
||||
if (applicant == null)
|
||||
{
|
||||
@@ -68,10 +68,10 @@ namespace DiscordApp.Justice.Interactions
|
||||
await channel.SendMessageAsync(embed: embed);
|
||||
}
|
||||
|
||||
[ModalInteraction("NewBizness")]
|
||||
[ModalInteraction("NewBiznessModal")]
|
||||
public async Task newBizness(INewBizness modal)
|
||||
{
|
||||
await DeferAsync(true);
|
||||
|
||||
Passport? applicant = await Startup.appDbContext.Passport.FindAsync(int.Parse(modal.passportId));
|
||||
|
||||
if (applicant == null)
|
||||
|
||||
@@ -28,8 +28,9 @@ namespace DiscordApp.Justice.Interactions
|
||||
[ModalInteraction("reworkpassportModal")]
|
||||
public async Task reCreatePassportInteraction(IReWorkPassportModal modal)
|
||||
{
|
||||
await DeferAsync(true);
|
||||
double passportId = modal.Id;
|
||||
|
||||
int passportId;
|
||||
int.TryParse(modal.Id, out passportId);
|
||||
bool recreatePassport = modal.IsNewPassport == 1;
|
||||
if (recreatePassport)
|
||||
{
|
||||
@@ -37,6 +38,7 @@ namespace DiscordApp.Justice.Interactions
|
||||
}
|
||||
else
|
||||
{
|
||||
if (passportId == null) { await FollowupAsync("Айди паспорта устаревший, используйте кнопку \"Создать новый\" для создания паспорта", ephemeral: true); return; }
|
||||
var passport = Startup.appDbContext.Passport.Where(x => x.Id == passportId).FirstOrDefault();
|
||||
if (passport == null) { await FollowupAsync("ID паспорта не правильный, или не существует.", ephemeral: true); return; }
|
||||
|
||||
@@ -113,7 +115,7 @@ namespace DiscordApp.Justice.Interactions
|
||||
[ModalInteraction("ReNewPassportModal")]
|
||||
public async Task renewPassportInteraction(INewPassportModal modal)
|
||||
{
|
||||
await DeferAsync(true);
|
||||
|
||||
string name = modal.NickName;
|
||||
string RpName = modal.RPName;
|
||||
int supporterInt = modal.Supporter;
|
||||
@@ -239,7 +241,7 @@ namespace DiscordApp.Justice.Interactions
|
||||
[ModalInteraction("passportModal")]
|
||||
public async Task createPassportInteraction(INewPassportModal modal)
|
||||
{
|
||||
await DeferAsync(true);
|
||||
|
||||
string name = modal.NickName;
|
||||
string RpName = modal.RPName;
|
||||
int supporterInt = modal.Supporter;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace DiscordApp.Justice.Interactions
|
||||
[ModalInteraction("newArtCallback")]
|
||||
public async Task newArtModalInteraction(INewArtModal modal)
|
||||
{
|
||||
await DeferAsync(true);
|
||||
|
||||
string name = modal.Name;
|
||||
string maps = modal.MapNumbers;
|
||||
string size = modal.Size;
|
||||
@@ -89,7 +89,7 @@ namespace DiscordApp.Justice.Interactions
|
||||
[ModalInteraction("newBookCallback")]
|
||||
public async Task newBookModalInteraction(INewBookModal modal)
|
||||
{
|
||||
await DeferAsync(true);
|
||||
|
||||
string name = modal.Name;
|
||||
string janre = modal.Janre;
|
||||
string annotation = modal.Annotation;
|
||||
|
||||
@@ -33,8 +33,8 @@ namespace DiscordApp.Justice.Modals
|
||||
public string Title => "Создание паспорта";
|
||||
|
||||
[InputLabel("ID паспорта")]
|
||||
[ModalTextInput("id", TextInputStyle.Short, placeholder: "82-777", maxLength: 7)]
|
||||
public double Id { get; set; }
|
||||
[ModalTextInput("id", TextInputStyle.Short, placeholder: "97166", maxLength: 7)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[InputLabel("Новые данные(0/1)")]
|
||||
[ModalTextInput("isNewPassportData", TextInputStyle.Short, placeholder: "1 - да, 0 - нет", maxLength: 1, initValue: "0")]
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Discord.Interactions;
|
||||
using Discord.WebSocket;
|
||||
using DiscordApp.Database;
|
||||
using Microsoft.VisualBasic;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
@@ -47,22 +48,16 @@ namespace DiscordApp
|
||||
try
|
||||
{
|
||||
var context = new SocketInteractionContext(client, interaction);
|
||||
|
||||
//await context.Interaction.DeferAsync(true);
|
||||
var result = await handler.ExecuteCommandAsync(context, services);
|
||||
|
||||
if (!result.IsSuccess)
|
||||
switch (result.Error)
|
||||
{
|
||||
case InteractionCommandError.UnmetPrecondition:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
await interaction.RespondAsync($"Возникла какая-то ошибка: {result.Error}", ephemeral: true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (interaction.Type is InteractionType.ApplicationCommand)
|
||||
await interaction.GetOriginalResponseAsync().ContinueWith(async (msg) => await msg.Result.DeleteAsync());
|
||||
await interaction.GetOriginalResponseAsync().ContinueWith(async (msg) => await msg.Result.DeleteAsync()); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user