Merge pull request #6 from Dultus/Fix27062023

Added Timer and Enabled multiple attributes on Methods.
This commit is contained in:
Dultus 2023-06-27 16:52:59 +02:00 committed by GitHub
commit 2e3a39b822
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 4 deletions

View file

@ -60,13 +60,16 @@ namespace Discord.Controller
{ {
methods.AddRange(type.GetMethods()); methods.AddRange(type.GetMethods());
} }
EventControllerAttribute<T>? attribute; List<EventControllerAttribute<T>>? attribute;
foreach (var method in methods) foreach (var method in methods)
{ {
attribute = method.GetCustomAttribute<EventControllerAttribute<T>>(); attribute = method.GetCustomAttributes<EventControllerAttribute<T>>().ToList();
if (attribute is not null && EqualityComparer<T>.Default.Equals(attribute.Event, category)) foreach (var attr in attribute)
{
if (EqualityComparer<T>.Default.Equals(attr.Event, category))
method.Invoke(null, new object[] { ids, e }); method.Invoke(null, new object[] { ids, e });
} }
} }
} }
}
} }

27
Discord/Helpers/Timer.cs Normal file
View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Discord.Helpers
{
internal class Timer
{
private System.Threading.Timer? timer;
public void SetUpTimer(TimeSpan alertTime,object passingObject, Action<object> method)
{
DateTime current = DateTime.Now;
TimeSpan timeToGo = alertTime - current.TimeOfDay;
if (timeToGo < TimeSpan.Zero)
{
return;//time already passed
}
this.timer = new System.Threading.Timer(x =>
{
method.Invoke(passingObject);
}, null, timeToGo, Timeout.InfiniteTimeSpan);
}
}
}