Skip to content

Commit 899cd32

Browse files
committed
Switch plugins away from using deprecated function event.async()
1 parent 5180238 commit 899cd32

4 files changed

Lines changed: 34 additions & 24 deletions

File tree

cloudbot/event.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def async_call(self, func, *args, **kwargs):
327327
if sys.version_info < (3, 7, 0):
328328
# noinspection PyCompatibility
329329
@asyncio.coroutine
330-
def async(self, function, *args, **kwargs):
330+
def async_(self, function, *args, **kwargs):
331331
warnings.warn(
332332
"event.async() is deprecated, use event.async_call() instead.",
333333
DeprecationWarning, stacklevel=2
@@ -336,6 +336,13 @@ def async(self, function, *args, **kwargs):
336336
return result
337337

338338

339+
# Silence deprecation warnings about use of the 'async' name as a function
340+
try:
341+
setattr(Event, 'async', getattr(Event, 'async_'))
342+
except AttributeError:
343+
pass
344+
345+
339346
class CommandEvent(Event):
340347
"""
341348
:type hook: cloudbot.plugin.CommandHook

cloudbot/plugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import sqlalchemy
1414
import sys
1515

16+
import time
17+
1618
from cloudbot.event import Event
1719
from cloudbot.hook import Priority, Action
1820
from cloudbot.util import database
@@ -649,6 +651,7 @@ def __init__(self, _type, plugin, func_hook):
649651
if sys.version_info < (3, 7, 0):
650652
if "async" in self.required_args:
651653
logger.warning("Use of deprecated function 'async' in %s", self.description)
654+
time.sleep(1)
652655
warnings.warn(
653656
"event.async() is deprecated, use event.async_call() instead.",
654657
DeprecationWarning, stacklevel=2

plugins/autojoin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def get_channels(db, conn):
2121

2222
@asyncio.coroutine
2323
@hook.irc_raw('004')
24-
def do_joins(db, conn, async):
25-
chans = yield from async(get_channels, db, conn)
24+
def do_joins(db, conn, async_call):
25+
chans = yield from async_call(get_channels, db, conn)
2626
join_throttle = conn.config.get("join_throttle", 0.4)
2727
for chan in chans:
2828
conn.join(chan[1])

plugins/remind.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,26 @@
4040

4141

4242
@asyncio.coroutine
43-
def delete_reminder(async, db, network, remind_time, user):
43+
def delete_reminder(async_call, db, network, remind_time, user):
4444
query = table.delete() \
4545
.where(table.c.network == network.lower()) \
4646
.where(table.c.remind_time == remind_time) \
4747
.where(table.c.added_user == user.lower())
48-
yield from async(db.execute, query)
49-
yield from async(db.commit)
48+
yield from async_call(db.execute, query)
49+
yield from async_call(db.commit)
5050

5151

5252
@asyncio.coroutine
53-
def delete_all(async, db, network, user):
53+
def delete_all(async_call, db, network, user):
5454
query = table.delete() \
5555
.where(table.c.network == network.lower()) \
5656
.where(table.c.added_user == user.lower())
57-
yield from async(db.execute, query)
58-
yield from async(db.commit)
57+
yield from async_call(db.execute, query)
58+
yield from async_call(db.commit)
5959

6060

6161
@asyncio.coroutine
62-
def add_reminder(async, db, network, added_user, added_chan, message, remind_time, added_time):
62+
def add_reminder(async_call, db, network, added_user, added_chan, message, remind_time, added_time):
6363
query = table.insert().values(
6464
network=network.lower(),
6565
added_user=added_user.lower(),
@@ -68,17 +68,17 @@ def add_reminder(async, db, network, added_user, added_chan, message, remind_tim
6868
message=message,
6969
remind_time=remind_time
7070
)
71-
yield from async(db.execute, query)
72-
yield from async(db.commit)
71+
yield from async_call(db.execute, query)
72+
yield from async_call(db.commit)
7373

7474

7575
@asyncio.coroutine
7676
@hook.on_start()
77-
def load_cache(async, db):
77+
def load_cache(async_call, db):
7878
global reminder_cache
7979
reminder_cache = []
8080

81-
for network, remind_time, added_time, user, message in (yield from async(_load_cache_db, db)):
81+
for network, remind_time, added_time, user, message in (yield from async_call(_load_cache_db, db)):
8282
reminder_cache.append((network, remind_time, added_time, user, message))
8383

8484

@@ -89,16 +89,16 @@ def _load_cache_db(db):
8989

9090
@asyncio.coroutine
9191
@hook.periodic(30, initial_interval=30)
92-
def check_reminders(bot, async, db):
92+
def check_reminders(bot, async_call, db):
9393
current_time = datetime.now()
9494

9595
for reminder in reminder_cache:
9696
network, remind_time, added_time, user, message = reminder
9797
if remind_time <= current_time:
9898
if network not in bot.connections:
9999
# connection is invalid
100-
yield from add_reminder(async, db, network, remind_time, user)
101-
yield from load_cache(async, db)
100+
yield from add_reminder(async_call, db, network, remind_time, user)
101+
yield from load_cache(async_call, db)
102102
continue
103103

104104
conn = bot.connections[network]
@@ -119,13 +119,13 @@ def check_reminders(bot, async, db):
119119
" it seems I was unable to deliver it on time)".format(late_time)
120120
conn.message(user, colors.parse(late))
121121

122-
yield from delete_reminder(async, db, network, remind_time, user)
123-
yield from load_cache(async, db)
122+
yield from delete_reminder(async_call, db, network, remind_time, user)
123+
yield from load_cache(async_call, db)
124124

125125

126126
@asyncio.coroutine
127127
@hook.command('remind', 'reminder', 'in')
128-
def remind(text, nick, chan, db, conn, notice, async):
128+
def remind(text, nick, chan, db, conn, notice, async_call):
129129
"""<1 minute, 30 seconds>: <do task> -- reminds you to <do task> in <1 minute, 30 seconds>"""
130130

131131
count = len([x for x in reminder_cache if x[0] == conn.name and x[3] == nick.lower()])
@@ -134,8 +134,8 @@ def remind(text, nick, chan, db, conn, notice, async):
134134
if count == 0:
135135
return "You have no reminders to delete."
136136

137-
yield from delete_all(async, db, conn.name, nick)
138-
yield from load_cache(async, db)
137+
yield from delete_all(async_call, db, conn.name, nick)
138+
yield from load_cache(async_call, db)
139139
return "Deleted all ({}) reminders for {}!".format(count, nick)
140140

141141
# split the input on the first ":"
@@ -171,8 +171,8 @@ def remind(text, nick, chan, db, conn, notice, async):
171171
return "I can't remind you in the past!"
172172

173173
# finally, add the reminder and send a confirmation message
174-
yield from add_reminder(async, db, conn.name, nick, chan, message, remind_time, current_time)
175-
yield from load_cache(async, db)
174+
yield from add_reminder(async_call, db, conn.name, nick, chan, message, remind_time, current_time)
175+
yield from load_cache(async_call, db)
176176

177177
remind_text = format_time(seconds, count=2)
178178
output = "Alright, I'll remind you \"{}\" in $(b){}$(clear)!".format(message, remind_text)

0 commit comments

Comments
 (0)