GoldyBot.ext.events

 1from __future__ import annotations
 2from typing import Dict, List
 3from functools import wraps
 4
 5import GoldyBot
 6
 7# Adding events to GoldyBot YAY!!!
 8# -----------------------------------
 9def on_join():
10    """Event that triggers when a member joins, uwu."""
11    def decorator(func):
12        @wraps(func)
13        def wrapper():
14            GoldyBot.cache.main_cache_dict["events"]["on_join"].append(func)
15        
16        return wrapper()
17    return decorator
18
19def on_leave():
20    """Event that triggers when a member leaves."""
21    def decorator(func):
22        @wraps(func)
23        def wrapper():
24            GoldyBot.cache.main_cache_dict["events"]["on_leave"].append(func)
25        
26        return wrapper()
27    return decorator
28
29
30class Events():
31    def __init__(self) :
32        pass
33
34    async def __trigger_functions(self, event_code_name:str, **args_to_pass_to_func):
35        for function in GoldyBot.cache.main_cache_dict["events"][f"{event_code_name}"]:
36        
37            # The function is in a class/maybe extension.
38            if list(function.__code__.co_varnames)[0] == "self":
39                await function(
40                    GoldyBot.cache.FindExtensions().find_object_by_extension_name(extension_name=str(function).split(" ")[1].split(".")[0]), 
41                    **args_to_pass_to_func
42                )
43            
44            else:
45                await function(**args_to_pass_to_func)
46
47
48    def register_all_nextcord_events(self):
49        client = GoldyBot.cache.client()
50
51        @client.event
52        async def on_member_join(member:GoldyBot.nextcord.Member):
53            member = GoldyBot.Member(ctx=None, member_object=member)
54
55            await self.__trigger_functions("on_join", member=member)
56
57        @client.event
58        async def on_member_remove(member:GoldyBot.nextcord.Member):
59            member = GoldyBot.Member(ctx=None, member_object=member)
60
61            await self.__trigger_functions("on_leave", member=member)
def on_join():
10def on_join():
11    """Event that triggers when a member joins, uwu."""
12    def decorator(func):
13        @wraps(func)
14        def wrapper():
15            GoldyBot.cache.main_cache_dict["events"]["on_join"].append(func)
16        
17        return wrapper()
18    return decorator

Event that triggers when a member joins, uwu.

def on_leave():
20def on_leave():
21    """Event that triggers when a member leaves."""
22    def decorator(func):
23        @wraps(func)
24        def wrapper():
25            GoldyBot.cache.main_cache_dict["events"]["on_leave"].append(func)
26        
27        return wrapper()
28    return decorator

Event that triggers when a member leaves.

class Events:
31class Events():
32    def __init__(self) :
33        pass
34
35    async def __trigger_functions(self, event_code_name:str, **args_to_pass_to_func):
36        for function in GoldyBot.cache.main_cache_dict["events"][f"{event_code_name}"]:
37        
38            # The function is in a class/maybe extension.
39            if list(function.__code__.co_varnames)[0] == "self":
40                await function(
41                    GoldyBot.cache.FindExtensions().find_object_by_extension_name(extension_name=str(function).split(" ")[1].split(".")[0]), 
42                    **args_to_pass_to_func
43                )
44            
45            else:
46                await function(**args_to_pass_to_func)
47
48
49    def register_all_nextcord_events(self):
50        client = GoldyBot.cache.client()
51
52        @client.event
53        async def on_member_join(member:GoldyBot.nextcord.Member):
54            member = GoldyBot.Member(ctx=None, member_object=member)
55
56            await self.__trigger_functions("on_join", member=member)
57
58        @client.event
59        async def on_member_remove(member:GoldyBot.nextcord.Member):
60            member = GoldyBot.Member(ctx=None, member_object=member)
61
62            await self.__trigger_functions("on_leave", member=member)
Events()
32    def __init__(self) :
33        pass
def register_all_nextcord_events(self):
49    def register_all_nextcord_events(self):
50        client = GoldyBot.cache.client()
51
52        @client.event
53        async def on_member_join(member:GoldyBot.nextcord.Member):
54            member = GoldyBot.Member(ctx=None, member_object=member)
55
56            await self.__trigger_functions("on_join", member=member)
57
58        @client.event
59        async def on_member_remove(member:GoldyBot.nextcord.Member):
60            member = GoldyBot.Member(ctx=None, member_object=member)
61
62            await self.__trigger_functions("on_leave", member=member)