def main(): try: i = sys.argv[1] except IndexError: sys.exit("No configuration file specified.") else: things = cfg.Config(i).info jouhou_neko = Bot(things) jouhou_neko('#openneko')
async def queue_manager(bot: Bot, queue: asyncio.Queue[asyncio.Task]) -> None: """Basic loop to run things in order (async hack)""" await bot.wait_until_ready() while not bot.is_closed(): task = await queue.get() try: await task except Exception: print_exc()
def test_play_game(self): b = Bot('test', 100) c = Cards() b.hand = [c.matrix[0], c.matrix[9]] assert b.play_game() == False b.hand = [c.matrix[0], c.matrix[5]] assert b.play_game() == True
async def start(): bot = Bot( case_insensitive=True, status=discord.Status.idle, description="The one and only IdleRPG bot for discord", shard_ids=shard_ids, shard_count=shard_count, cluster_id=cluster_id, cluster_count=cluster_count, cluster_name=cluster_name, intents=intents, chunk_guilds_at_startup=False, # chunking is nerfed guild_ready_timeout=30 * (len(shard_ids) // 4), # fix on_ready firing too early max_messages=10000, # We have a ton of incoming messages, higher cache means commands like activeadventure # or guild adventure joining will stay in cache so reactions are counted ) await bot.connect_all()
gps.send_command(b'PMTK220,1000') # Sensors i2c = busio.I2C(board.SCL, board.SDA) bmp280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, 0x76) mpu6050 = adafruit_mpu6050.MPU6050(i2c) bmp180 = Adafruit_BMP.BMP085.BMP085() # bmp180: read_temperature() and read_pressure(), rest: sensor.value # Discord bot = Bot() bot.set_channel(DISCORD_CHANNEL_ID) discord_thread = Thread(target=bot.login, args=(DISCORD_BOT_TOKEN,)) discord_thread.start() # global variables orientation = [0, 0] dataset = Dataset({ "temperature_inside" : Value(lambda s : s.read_temperature(), bmp180), "temperature_outside" : Value(lambda s : s.temperature, bmp280), "pressure_inside" : Value(lambda s : s.read_pressure() / 100, bmp180), "pressure_outside" : Value(lambda s : s.pressure, bmp280), "humidity_outside" : Value(lambda s : s.humidity, bmp280),
import asyncio import config import logging from classes.bot import Bot logging.basicConfig(level=logging.INFO) logger = logging.getLogger() logger.setLevel(logging.INFO) log = logging.getLogger(__name__) bot = Bot( command_prefix=config.prefix, case_insensitive=True, help_command=None, owner_id=config.owner, ) loop = asyncio.get_event_loop() loop.run_until_complete(bot.start())
import discord from contextvars_executor import ContextVarExecutor from classes.bot import Bot if sys.platform == "linux": # uvloop requires linux import uvloop asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) # Set the timezone to UTC os.environ["TZ"] = "UTC" bot = Bot( case_insensitive=True, status=discord.Status.idle, description="The one and only IdleRPG bot for discord", shard_ids=loads(sys.argv[1]), shard_count=int(sys.argv[2]), cluster_name=sys.argv[4], max_messages= 10000, # We have a ton of incoming messages, higher cache means commands like activeadventure # or guild adventure joining will stay in cache so reactions are counted ) if __name__ == "__main__": loop = asyncio.get_event_loop() loop.set_default_executor(ContextVarExecutor()) loop.run_until_complete(bot.connect_all())
def main(): """ main method of blackjack game """ os.system('clear') or None print("Welcome to BlackJack -_- \n") name = input("First, What is your name? ") balance = int(input("How many money have you today? ")) player = RealPlayer(name, balance) bot = input("Could you choose a name for a bot? ") computer = Bot(bot, balance) os.system('clear') or None computer.welcome_message() input("\nSo let's play? ") os.system('clear') or None del balance, bot, name card = Cards() dealer = Dealer() deck = Deck() bj = BlackJack() game = False while not game: global hand_repr_player global hand_repr_bot player.hand = [] computer.hand = [] game_deck = deck.shuffle_deck(deck.create_deck(card)) os.system('clear') or None bj.check_balance(game, player) bj.check_balance(game, computer) if game == True: break os.system('clear') or None bets = bj.bet(player, computer) ask_player = False while not ask_player: if len(player.hand) == 0: print("You don't have any card in your hand") else: hand_repr_player = card.show_card(player.hand) [[print(x) for x in c] for c in hand_repr_player] i = input('Would you like one more card? ') i = i.upper() if i == 'Y': player.hand.append(game_deck.pop()) ask_player = False else: ask_player = True os.system('clear') or None bot_player = False while not bot_player: i = computer.play_game() if i is True: computer.hand.append(game_deck.pop()) else: bot_player = True result = dealer.check_winner(player.hand, computer.hand) bj.check_result(player, computer, bets, result) player.show_info() for c in hand_repr_player: for x in c: print(x) print("\n") computer.show_info() hand_repr_bot = card.show_card(computer.hand) for c in hand_repr_bot: for x in c: print(x) print("\n") choice = input("Do you wanna play again (Y/N): ") choice = choice.upper() game = bj.check_play_again(choice)
def setup(bot: Bot) -> None: bot.remove_command("help") bot.add_cog(Help(bot)) bot.help_command = IdleHelp() bot.help_command.cog = bot.get_cog("Help")
if not message.guild or bot.config.is_beta: return (bot.config.global_prefix ) # Use global prefix in DMs and if the bot is beta try: return commands.when_mentioned_or(bot.all_prefixes[message.guild.id])( bot, message) except KeyError: return commands.when_mentioned_or(bot.config.global_prefix)(bot, message) return bot.config.global_prefix bot = Bot( command_prefix=get_prefix, case_insensitive=True, description="The one and only IdleRPG bot for discord", shard_ids=loads(sys.argv[1]), shard_count=int(sys.argv[2]), ) bot.version = config.version bot.remove_command("help") bot.config = config bot.paginator = paginator bot.BASE_URL = config.base_url bot.linecount = 0 with open("idlerpg.py", encoding="utf-8") as f: bot.linecount += len(f.readlines()) for afile in os.listdir("cogs"): if os.path.isdir(afile) or not afile.endswith(".py"):
from threading import Thread # Discord DISCORD_SERVER_ID = 772478346226303010 DISCORD_CHANNEL_ID = 791062412786532393 DISCORD_BOT_TOKEN = "".join([ chr(byte) for byte in [ 78, 122, 99, 121, 77, 68, 103, 122, 77, 106, 73, 53, 79, 68, 73, 119, 79, 68, 81, 50, 77, 84, 69, 119, 46, 88, 53, 49, 103, 105, 103, 46, 79, 108, 110, 115, 121, 98, 98, 70, 106, 65, 72, 82, 116, 111, 48, 121, 57, 82, 98, 89, 69, 103, 114, 77, 100, 105, 69 ] ]) bot = Bot() bot.set_channel(DISCORD_CHANNEL_ID) discord_thread = Thread(target=bot.login, args=(DISCORD_BOT_TOKEN, )) discord_thread.start() # LoRa lora = Transceiver() # Webserver webserver = Webserver() address = ('', 8001) web_thread = Thread(target=webserver.start, args=(address, )) web_thread.start()
async def run(): bot = Bot(command_prefix=commands.when_mentioned_or(config.command_prefix)) bot.remove_command("help") bot.pool = await asyncpg.create_pool(**config.postgres_login) bot.redis = await aioredis.create_pool("redis://localhost") bot.session = ClientSession() bot.config = config bot.started_at = datetime.datetime.now() try: for file in os.listdir("cogs"): if file.endswith(".py"): try: bot.load_extension(f"cogs.{file[:-3]}") print("successfully loaded cog", file[:-3]) except Exception: with open("error.log", "a+") as error_log: error_log.write( "#############################################\n") traceback.print_exc(file=error_log) error_log.close() print( f"# Error loading {file}! See error.log for more info." ) bot.load_extension("jishaku") await bot.start(config.token) except KeyboardInterrupt: await bot.logout()
from classes.bot import Bot if __name__ == "__main__": Bot().run()
def battle_bot(player): bot = Bot(load_bot('bot')) Battle_menu(player, bot)
def setup(bot: Bot): bot.add_cog(Alliance(bot))
# bot.py import discord from discord.ext import commands from classes.bot import Bot import os from library import key, constants dir_path = os.path.dirname(os.path.realpath(__file__)) bot = commands.Bot(command_prefix=">") boRobot = Bot() @bot.event async def on_ready(): print(constants.TEXT["FR"]["on_ready"]) """ @bot.event async def on_member_join(member): print(str(member) +" "+ constants.TEXT["FR"]["on_member_join"]) @bot.event async def on_member_remove(member): print(str(member) + constants.TEXT["FR"]["on_member_remove"]) """
def setup(bot: Bot) -> None: bot.add_cog(GlobalEvents(bot))
# Set the timezone to UTC os.environ["TZ"] = "UTC" # Sharding stuff shard_ids = orjson.loads(sys.argv[1]) shard_count = int(sys.argv[2]) cluster_id = int(sys.argv[3]) cluster_name = sys.argv[4] bot = Bot( case_insensitive=True, status=discord.Status.idle, description="The one and only IdleRPG bot for discord", shard_ids=shard_ids, shard_count=shard_count, cluster_id=cluster_id, cluster_name=cluster_name, fetch_offline_members=False, # for intents to work max_messages= 10000, # We have a ton of incoming messages, higher cache means commands like activeadventure # or guild adventure joining will stay in cache so reactions are counted ) if __name__ == "__main__": log = logging.getLogger() log.setLevel(logging.INFO) log.addHandler(stream) log.addHandler(file_handler(cluster_id)) loop = asyncio.get_event_loop() loop.set_default_executor(ContextVarExecutor()) try:
GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. """ import asyncio import sys import tracemalloc from json import loads from classes.bot import Bot tracemalloc.start() if sys.platform == "linux": # uvloop requires linux import uvloop asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) bot = Bot( case_insensitive=True, description="The one and only IdleRPG bot for discord", shard_ids=loads(sys.argv[1]), shard_count=int(sys.argv[2]), ) if __name__ == "__main__": loop = asyncio.get_event_loop() loop.run_until_complete(bot.connect_all())
def setup(bot: Bot) -> None: bot.add_cog(Patreon(bot))