Merge pull request #6 from Dultus/Fix27062023
Added Timer and Enabled multiple attributes on Methods.
This commit is contained in:
commit
2e3a39b822
2 changed files with 34 additions and 4 deletions
|
|
@ -60,13 +60,16 @@ namespace Discord.Controller
|
|||
{
|
||||
methods.AddRange(type.GetMethods());
|
||||
}
|
||||
EventControllerAttribute<T>? attribute;
|
||||
List<EventControllerAttribute<T>>? attribute;
|
||||
foreach (var method in methods)
|
||||
{
|
||||
attribute = method.GetCustomAttribute<EventControllerAttribute<T>>();
|
||||
if (attribute is not null && EqualityComparer<T>.Default.Equals(attribute.Event, category))
|
||||
attribute = method.GetCustomAttributes<EventControllerAttribute<T>>().ToList();
|
||||
foreach (var attr in attribute)
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(attr.Event, category))
|
||||
method.Invoke(null, new object[] { ids, e });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
27
Discord/Helpers/Timer.cs
Normal file
27
Discord/Helpers/Timer.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue