Refactoring a Python Bot [Live Coding Recap]

Live Coding Stream Recaps (14 Part Series)

1 Unique reactions to Twitch raids [Live Coding Recap]
2 Faking a computer glitch w/Python & OBS [Live Coding Recap]
10 more parts…
3 Shout-out chat bot in Python [Live Coding Recap]
4 Greeting subscribers w/the Twitch shoutout bot [Live Coding Recap]
5 Adding TTS to the Twitch Shoutout Bot [Live Coding Recap]
6 Twitch Bot 101 (Python) [Live Coding Recap]
7 Persistent Data w/JSON [Live Coding Recap]
8 Storing Bot Commands in JSON Objects [Live Coding Recap]
9 A Better Quoting System [Live Coding Recap]
10 Refactoring a Python Bot [Live Coding Recap]
11 Are you a 10x Developer? [Live Coding Recap]
12 SFX & Derp Wars (a Dope Wars clone) [Live Coding Recap]
13 A Text-Based Battle Royale?? [Live Coding Recap]
14 Learning C# w/ @AlSweigart [Live Coding Recap]

Streamed: 10/29 on Twitch

Topic(s): We hung out & refactored DeepThonk (the python bot’s) code!
Language: Python, JSON
Tech & libs used: VSCode, TwitchIO

You can find the notes and code from stream down below! 😀

StarProject Repository
Follow ⇒ on Twitch and GitHub
WatchTwitch VOD (replay)

During the stream we…

moved !project from FAQ’s into it’s own command
made !project settable from chat
moved all other commands to commands.py
cleaned up commands & commented uncommented funcs
created a command module and moved all commands in there
created a command to enable/disable shoutouts
created a !raider command to thank (and shoutout) raiders!

Here’s some of the code we wrote…

Shoutouts can be a little too much sometimes when we’re actively developing the bot, so we created a chat function to turn them on or off on the fly.

# in commands.cmds @bot.command(name='shoutouts')
async def shoutouts(ctx):
    'toggles shoutouts on or off'
    if data.get_setting('shoutouts'):
        data.set_setting('shoutouts', False)
        await ctx.send('Shoutouts are off now.')
    else:
        data.set_setting('shoutouts', True)
        await ctx.send('Shoutouts are back on!')

Enter fullscreen mode Exit fullscreen mode

And, at the recommendation of chat, we created a command to shout out (and thank) raiders.

# in commands.cmds @bot.command(name='raider')
async def raider(ctx):
    'shouts & thanks raiders'
    token = ctx.content.split(' ', 1)
    if token[1][0] == '@':  # strip @'s if they passed in user name arg with one         raider = token[1][1:]
    else:
        raider = token[1]
    msg = f"ninjab1Bigups to @{raider} for the sick raid! Check them out at https://twitch.tv/{raider}"
    await ctx.send(msg)

Enter fullscreen mode Exit fullscreen mode

Live Coding Stream Recaps (14 Part Series)

1 Unique reactions to Twitch raids [Live Coding Recap]
2 Faking a computer glitch w/Python & OBS [Live Coding Recap]
10 more parts…
3 Shout-out chat bot in Python [Live Coding Recap]
4 Greeting subscribers w/the Twitch shoutout bot [Live Coding Recap]
5 Adding TTS to the Twitch Shoutout Bot [Live Coding Recap]
6 Twitch Bot 101 (Python) [Live Coding Recap]
7 Persistent Data w/JSON [Live Coding Recap]
8 Storing Bot Commands in JSON Objects [Live Coding Recap]
9 A Better Quoting System [Live Coding Recap]
10 Refactoring a Python Bot [Live Coding Recap]
11 Are you a 10x Developer? [Live Coding Recap]
12 SFX & Derp Wars (a Dope Wars clone) [Live Coding Recap]
13 A Text-Based Battle Royale?? [Live Coding Recap]
14 Learning C# w/ @AlSweigart [Live Coding Recap]

原文链接:Refactoring a Python Bot [Live Coding Recap]

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容